Closed krigbaum closed 9 years ago
From the following lines:
char *outstr = NULL;
ssize_t bytes_read = 0;
plfs_error = plfs_write(fd, outstr, size, offset, pid, &bytes_read); // This should be plfs_read()
I think that you forget to allocate storage space for the 'outstr', so it's a NULL pointer and which is not correct for plfs_read(). And you use plfs_write instead of plfs_read mistakenly. You can try code like this to allocate the output buffer at stack:
char outstr[16];
ssize_t bytes_read = 0;
printf("Executing 'plfs_read(0x%0x, \"%s\", %d, %d, %d, %d)'\n", fd, outstr, size, offset, pid, bytes_read);
plfs_error = plfs_read(fd, outstr, size, offset, pid, &bytes_read);
Thanks, Zhang. That was pretty dense of me. Unfortunately, it still doesn't seem to be quite correct for some reason. After making the change you suggested, even though plfs_error is 0 and bytes read is 5, outstr still has whatever garbage was in it after the declaration. If I initialize it, the initialized value is returned. What's very interesting, is that in a different context (from ldplfs) if I preload the return buffer with "dummy" and pass it to plfs_read to read 3 characters, it returns "xxxmy" which indicates to me that plfs is returning only the z's that it uses to initialize it's buffer. Anyway, here is the altered code and output:
int main(int argc, char *argv) { const char cpath = "/tmp/local_plfs/test.plfs.fil"; //mode_t fmode = "w+"; mode_t fmode = 0666; Plfs_fd *fd = NULL;
//printf("fd = 0x%0x\n", fd);
//printf("cpath = %s\n", cpath);
//printf("O_RDWR = %d\n", O_RDWR);
//printf("getpid() = %d\n", getpid());
//printf("fmode = %d\n", fmode);
printf("Executing 'plfs_open(0x%0x, \"%s\", %d, %d, %d, NULL)'\n",
fd, cpath, O_RDWR, getpid(), fmode); plfs_error_t plfs_error = plfs_open(&fd, cpath, O_RDWR, getpid(), fmode, NULL); printf("plfs_error = %d\n", plfs_error); printf("fd = 0x%0x\n\n", fd);
const char *str = "Hello";
const int size = strlen(str);
const int offset = 0;
const pid_t pid = getpid();
ssize_t written = 0;
printf("Executing 'plfs_write(0x%0x, %0x0x, %d, %d, %d, %d)'\n", fd,
str, size, offset, pid, written); plfs_error = plfs_write(fd, str, size, offset, pid, &written); printf("plfs_error = %d\n", plfs_error); printf("written = %d\n\n", written);
char outstr[16];
//outstr[0] = '\0';
//strcpy(outstr, "abcdefghijklm");
ssize_t bytes_read = 0;
printf("outstr = %s\n", outstr);
printf("Executing 'plfs_read(0x%0x, 0x%0x, %d, %d, %d, %d)'\n", fd,
outstr, size, offset, pid, bytes_read); plfs_error = plfs_write(fd, outstr, size, offset, pid, &bytes_read); printf("plfs_error = %d\n", plfs_error); printf("bytes_read = %d\n", bytes_read); printf("outstr = %s\n\n ", outstr);
Plfs_close_opt opts;
int x;
printf("Executing 'plfs_close(0x%0x, %d, %d, %d, %d, NULL)'\n", fd,
pid, getuid(), O_RDWR, NULL, x); plfs_error = plfs_close(fd, pid, getuid(), O_RDWR, NULL, &x); printf("plfs_error = %d\n", plfs_error);
return SUCCESS;
}
Executing 'plfs_open(0x0, "/tmp/local_plfs/test.plfs.fil", 2, 54673, 438, NULL)' plfs_error = 0 fd = 0x24c88e0
Executing 'plfs_write(0x24c88e0, 400c5c0x, 5, 0, 54673, 0)' plfs_error = 0 written = 5
outstr = N�8YD+ Executing 'plfs_read(0x24c88e0, 0x4a2de670, 5, 0, 54673, 0)' plfs_error = 0 bytes_read = 5 outstr = N�8YD+
Executing 'plfs_close(0x24c88e0, 54673, 55096, 2, 0, NULL)' plfs_error = 0
On Mon, 2015-03-16 at 18:41 -0700, Zhang Jingwang wrote:
From the following lines:
char *outstr = NULL; ssize_t bytes_read = 0;
plfs_error = plfs_write(fd, outstr, size, offset, pid, &bytes_read);
I think that you forget to allocate storage space for the 'outstr', so it's a NULL pointer and which is not correct for plfs_read(). You can try code like this to allocate the output buffer at stack:
char outstr[16]; ssize_t bytes_read = 0;
printf("Executing 'plfs_read(0x%0x, \"%s\", %d, %d, %d, %d)'\n", fd, outstr, size, offset, pid, bytes_read); plfs_error = plfs_write(fd, outstr, size, offset, pid, &bytes_read);
— Reply to this email directly or view it on GitHub.
I will consult with someone today that may be able to talk to the developer of small file mode.
Alfred
From: krigbaum notifications@github.com<mailto:notifications@github.com> Reply-To: plfs/plfs-core reply@reply.github.com<mailto:reply@reply.github.com> Date: Tue, 17 Mar 2015 05:40:56 -0700 To: plfs/plfs-core plfs-core@noreply.github.com<mailto:plfs-core@noreply.github.com> Subject: Re: [plfs-core] plfs_read not working with small files (#360)
Thanks, Zhang. That was pretty dense of me. Unfortunately, it still doesn't seem to be quite correct for some reason. After making the change you suggested, even though plfs_error is 0 and bytes read is 5, outstr still has whatever garbage was in it after the declaration. If I initialize it, the initialized value is returned. What's very interesting, is that in a different context (from ldplfs) if I preload the return buffer with "dummy" and pass it to plfs_read to read 3 characters, it returns "xxxmy" which indicates to me that plfs is returning only the z's that it uses to initialize it's buffer. Anyway, here is the altered code and output:
int main(int argc, char *argv) { const char cpath = "/tmp/local_plfs/test.plfs.fil"; //mode_t fmode = "w+"; mode_t fmode = 0666; Plfs_fd *fd = NULL;
//printf("fd = 0x%0x\n", fd); //printf("cpath = %s\n", cpath); //printf("O_RDWR = %d\n", O_RDWR); //printf("getpid() = %d\n", getpid()); //printf("fmode = %d\n", fmode);
printf("Executing 'plfs_open(0x%0x, \"%s\", %d, %d, %d, NULL)'\n", fd, cpath, O_RDWR, getpid(), fmode); plfs_error_t plfs_error = plfs_open(&fd, cpath, O_RDWR, getpid(), fmode, NULL); printf("plfs_error = %d\n", plfs_error); printf("fd = 0x%0x\n\n", fd);
const char *str = "Hello"; const int size = strlen(str); const int offset = 0; const pid_t pid = getpid(); ssize_t written = 0;
printf("Executing 'plfs_write(0x%0x, %0x0x, %d, %d, %d, %d)'\n", fd, str, size, offset, pid, written); plfs_error = plfs_write(fd, str, size, offset, pid, &written); printf("plfs_error = %d\n", plfs_error); printf("written = %d\n\n", written);
char outstr[16]; //outstr[0] = '\0'; //strcpy(outstr, "abcdefghijklm"); ssize_t bytes_read = 0;
printf("outstr = %s\n", outstr); printf("Executing 'plfs_read(0x%0x, 0x%0x, %d, %d, %d, %d)'\n", fd, outstr, size, offset, pid, bytes_read); plfs_error = plfs_write(fd, outstr, size, offset, pid, &bytes_read); printf("plfs_error = %d\n", plfs_error); printf("bytes_read = %d\n", bytes_read); printf("outstr = %s\n\n ", outstr);
Plfs_close_opt opts; int x; printf("Executing 'plfs_close(0x%0x, %d, %d, %d, %d, NULL)'\n", fd, pid, getuid(), O_RDWR, NULL, x); plfs_error = plfs_close(fd, pid, getuid(), O_RDWR, NULL, &x); printf("plfs_error = %d\n", plfs_error);
return SUCCESS; }
Executing 'plfs_open(0x0, "/tmp/local_plfs/test.plfs.fil", 2, 54673, 438, NULL)' plfs_error = 0 fd = 0x24c88e0
Executing 'plfs_write(0x24c88e0, 400c5c0x, 5, 0, 54673, 0)' plfs_error = 0 written = 5
outstr = N�8YD+ Executing 'plfs_read(0x24c88e0, 0x4a2de670, 5, 0, 54673, 0)' plfs_error = 0 bytes_read = 5 outstr = N�8YD+
Executing 'plfs_close(0x24c88e0, 54673, 55096, 2, 0, NULL)' plfs_error = 0
On Mon, 2015-03-16 at 18:41 -0700, Zhang Jingwang wrote:
From the following lines:
char *outstr = NULL; ssize_t bytes_read = 0;
plfs_error = plfs_write(fd, outstr, size, offset, pid, &bytes_read);
I think that you forget to allocate storage space for the 'outstr', so it's a NULL pointer and which is not correct for plfs_read(). You can try code like this to allocate the output buffer at stack:
char outstr[16]; ssize_t bytes_read = 0;
printf("Executing 'plfs_read(0x%0x, \"%s\", %d, %d, %d, %d)'\n", fd, outstr, size, offset, pid, bytes_read); plfs_error = plfs_write(fd, outstr, size, offset, pid, &bytes_read);
— Reply to this email directly or view it on GitHub.
— Reply to this email directly or view it on GitHubhttps://github.com/plfs/plfs-core/issues/360#issuecomment-82323758.
hi-
you are printing "Executing plfs_read" but you appear to
actually be calling plfs_write()?
chuck
On Tue, Mar 17, 2015 at 05:40:57AM -0700, krigbaum wrote:
printf("outstr = %s\n", outstr); printf("Executing 'plfs_read(0x%0x, 0x%0x, %d, %d, %d, %d)'\n", fd,
outstr, size, offset, pid, bytes_read); plfs_error = plfs_write(fd, outstr, size, offset, pid, &bytes_read); ^^^^^^^^^^^ printf("plfs_error = %d\n", plfs_error); printf("bytes_read = %d\n", bytes_read); printf("outstr = %s\n\n ", outstr);
Thanks. Excuse me while I go find a rock to hide under.
On Tue, 2015-03-17 at 06:37 -0700, chuckcranor wrote:
hi-
you are printing "Executing plfs_read" but you appear to actually be calling plfs_write()?
chuck
On Tue, Mar 17, 2015 at 05:40:57AM -0700, krigbaum wrote:
printf("outstr = %s\n", outstr); printf("Executing 'plfs_read(0x%0x, 0x%0x, %d, %d, %d, %d)'\n", fd, outstr, size, offset, pid, bytes_read); plfs_error = plfs_write(fd, outstr, size, offset, pid, &bytes_read); ^^^^^^^^^^^ printf("plfs_error = %d\n", plfs_error); printf("bytes_read = %d\n", bytes_read); printf("outstr = %s\n\n ", outstr);
— Reply to this email directly or view it on GitHub.
We are having trouble getting plfs_read to work correctly with small files. Sample test code in native PLFS is:
include
include
include
include
include <sys/types.h>
define SUCCESS 0
int main(int argc, char *argv) { const char cpath = "/tmp/local_plfs/test.plfs.fil"; //mode_t fmode = "w+"; mode_t fmode = 0666; Plfs_fd *fd = NULL;
}
The output from the test is:
Executing 'plfs_open(0x0, "/tmp/local_plfs/test.plfs.fil", 2, 36923, 438, NULL)' plfs_error = 0 fd = 0x1e6af70
Executing 'plfs_write(0x1e6af70, "Hello", 5, 0, 36923, 0)' plfs_error = 0 written = 5
Executing 'plfs_read(0x1e6af70, "(null)", 5, 0, 36923, 0)' plfs_error = 300 bytes_read = -1 outstr = (null)
Executing 'plfs_close(0x1e6af70, 36923, 55096, 2, 0, NULL)' plfs_error = 0
The plfsrc file is: