Hi group: I need some help! I use samba 4.5.8 And I mount a samba directory from CentOS 7. When I run such program in the mounted directory: ``` #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <fcntl.h> #include <string.h> int main() { printf("open aaa\n"); int fd = open("aaa", O_RDONLY | O_DIRECTORY, 0); if (fd < 0) { perror("open aaa"); } printf("sync aaa\n"); if(fsync(fd)) { perror("sync aaa"); } printf("OK\n"); return 0; } ``` I get such error: `sync aaa: Invalid argument` Is this expected for samba? Thanks in advance! Best Regards Cao
On Fri, Feb 02, 2018 at 08:34:29PM +0800, 曹树烽 via samba wrote:> Hi group: > I need some help! > I use samba 4.5.8 > And I mount a samba directory from CentOS 7. > > When I run such program in the mounted directory: > ``` > > #include <stdlib.h> > #include <stdio.h> > #include <errno.h> > #include <fcntl.h> > #include <string.h> > int main() { > printf("open aaa\n"); > int fd = open("aaa", O_RDONLY | O_DIRECTORY, 0); > if (fd < 0) { > perror("open aaa"); > } > printf("sync aaa\n"); > if(fsync(fd)) { > perror("sync aaa"); > } > printf("OK\n"); > return 0; > } > > ``` > I get such error: `sync aaa: Invalid argument` > Is this expected for samba? > Thanks in advance!Can you show us the wireshark trace and the smbd logs from this please ?
Hi! Afair, fsync()ing a directory is subject to platform-specific and implementation-defined behaviour, and may either - work as you'd want and (probably) expect - fail with an error - fail silently at least if your application targets more than one operating system/kernel - and even on one and the same platform, different filesystems might exhibit sublty different patterns of behaviour. So whatever you do, it's probably best to assume that the fsync() operation on your dir fd is going to fail, and route around that (potential) failure as best as you can. It still can be beneficial to try fsync()ing to try as hard as possibe to get operations against the directory as consistent as possible in face of a potential crash. Hth! -- with best regards: - Johannes Truschnigg ( johannes at truschnigg.info ) www: johannes.truschnigg.info phone: +43 650 2 133337 xmpp: johannes at truschnigg.info Please do not bother me with HTML-email or attachments. Thank you. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <lists.samba.org/pipermail/samba/attachments/20180202/2f131c14/signature.sig>
Hi, Jeremy: > Can you show us the wireshark trace and the smbd logs Sorry that I don't known how to use wireshark now. I have the ptrace log: ``` execve("/home/fujitsu/a.out", ["/home/fujitsu/a.out"], [/* 22 vars */]) = 0 brk(0) = 0x8ce000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f27a257d000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=73077, ...}) = 0 mmap(NULL, 73077, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f27a256b000 close(3) = 0 open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\34\2\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=2116736, ...}) = 0 mmap(NULL, 3932672, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f27a1f9e000 mprotect(0x7f27a2154000, 2097152, PROT_NONE) = 0 mmap(0x7f27a2354000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b6000) = 0x7f27a2354000 mmap(0x7f27a235a000, 16896, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f27a235a000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f27a256a000 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f27a2568000 arch_prctl(ARCH_SET_FS, 0x7f27a2568740) = 0 mprotect(0x7f27a2354000, 16384, PROT_READ) = 0 mprotect(0x600000, 4096, PROT_READ) = 0 mprotect(0x7f27a257e000, 4096, PROT_READ) = 0 munmap(0x7f27a256b000, 73077) = 0 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f27a257c000 write(1, "open aaa\n", 9open aaa ) = 9 open("aaa", O_RDONLY|O_DIRECTORY) = 3 write(1, "sync aaa\n", 9sync aaa ) = 9 fsync(3) = -1 EINVAL (Invalid argument) dup(2) = 4 fcntl(4, F_GETFL) = 0x8002 (flags O_RDWR|O_LARGEFILE) brk(0) = 0x8ce000 brk(0x8ef000) = 0x8ef000 brk(0) = 0x8ef000 fstat(4, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f27a257b000 write(4, "sync aaa: Invalid argument\n", 27sync aaa: Invalid argument ) = 27 close(4) = 0 munmap(0x7f27a257b000, 4096) = 0 write(1, "OK\n", 3OK ) = 3 exit_group(0) = ? +++ exited with 0 +++ ``` Best Regards Cao 在 2018年02月02日 20:54, Jeremy Allison 写道:> On Fri, Feb 02, 2018 at 08:34:29PM +0800, 曹树烽 via samba wrote: >> Hi group: >> I need some help! >> I use samba 4.5.8 >> And I mount a samba directory from CentOS 7. >> >> When I run such program in the mounted directory: >> ``` >> >> #include <stdlib.h> >> #include <stdio.h> >> #include <errno.h> >> #include <fcntl.h> >> #include <string.h> >> int main() { >> printf("open aaa\n"); >> int fd = open("aaa", O_RDONLY | O_DIRECTORY, 0); >> if (fd < 0) { >> perror("open aaa"); >> } >> printf("sync aaa\n"); >> if(fsync(fd)) { >> perror("sync aaa"); >> } >> printf("OK\n"); >> return 0; >> } >> >> ``` >> I get such error: `sync aaa: Invalid argument` >> Is this expected for samba? >> Thanks in advance! > Can you show us the wireshark trace and the smbd logs > from this please ? > > >
Hi, Johannes:> So whatever you do, it's probably best to assume that the fsync() operation on > your dir fd is going to fail, and route around that (potential) failure as > best as you can.Thanks very much for this information. Is this documented? So that I can report this to my boss. I googled this for sort of time. Thanks again! Best Regards Cao 在 2018年02月02日 20:59, Johannes Truschnigg 写道:> Hi! > > Afair, fsync()ing a directory is subject to platform-specific and > implementation-defined behaviour, and may either > > - work as you'd want and (probably) expect > - fail with an error > - fail silently > > at least if your application targets more than one operating system/kernel - > and even on one and the same platform, different filesystems might exhibit > sublty different patterns of behaviour. > > So whatever you do, it's probably best to assume that the fsync() operation on > your dir fd is going to fail, and route around that (potential) failure as > best as you can. > > It still can be beneficial to try fsync()ing to try as hard as possibe to get > operations against the directory as consistent as possible in face of a > potential crash. > > Hth! >