This seems like a bug. My guess is that either status2() shouldn't
return O_TRUNC, or it shouldn't be saved in the fd to begin with.
O_TRUNC is a transitory flag, only useful at the time of the open itself.
Fixing the common status2() is simplest; otherwise we need to fix all
the FSALs.
Daniel
On 10/12/2018 08:12 PM, Pradeep wrote:
Hello,
I'm seeing an issue with a specific application flow and with ganesha
server (2.6.5). Here is what the application does:
- fd1 = open (file1, O_WRONLY|O_CREAT|O_TRUNC)
Ganesha creates a state and stores the flags in fd->openflags (see
vfs_open2())
- write (fd1, ....)
- fd2 = open(file1, O_RDONLY)
Ganesha finds the state for the first open, finds the flags and calls
fsal_reopen2() with old and new flags OR'd together. This causes the
file to be truncated because the original open was done with O_TRUNC.
I don't see this behavior with kernel NFS or a local filesystem. Any
suggestions on fixing this? Here is a quick and dirty program to
reproduce it - you can see that the second stat prints zero as size with
a mount from Ganesha server.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char **argv)
{
char *fn = argv[1];
int fd;
char buf[1024];
struct stat stbuf;
int rc;
fd = open(fn, O_WRONLY|O_CREAT|O_TRUNC, 0666);
printf("open(%s) = %d\n", fn, fd);
ssize_t ret;
ret = write(fd, buf, sizeof(buf));
printf("write returned %ld\n", ret);
rc = stat(fn, &stbuf);
printf("size: %ld\n", stbuf.st_size);
int fd1;
fd1 = open(fn, O_RDONLY);
printf("open(%s) = %d\n", fn, fd1);
rc = stat(fn, &stbuf);
printf("size: %ld\n", stbuf.st_size);
}
Thanks,
Pradeep
_______________________________________________
Devel mailing list -- devel(a)lists.nfs-ganesha.org
To unsubscribe send an email to devel-leave(a)lists.nfs-ganesha.org