When removing all files in a large NFS mounted directory by calling readdir and unlink repeatedly files get skipped. It seems that this problem is related to problem kern/3381. I ran into this problem when running bonnie++ (www.cooker.com.au/bonnie++) on a NFS mounted filesystem. Fix: Call rewinddir after each unlink call. I consider this a workaround, not a fix. How-To-Repeat: Run the attached program on the client. Uncomment the rewinddir call first. ---- snip ----- #include <stdio.h> #include <fcntl.h> #include <sys/types.h> #include <dirent.h> #define BASEDIR "/FS/testdir" /* NFS mounted */ #define NFILES 1024 main() { create_files(); delete_files(); } create_files() { int i,fd; char buf[2048]; for(i = 0 ; i < NFILES ; i++) { snprintf(buf,2048,"%s/%04d",BASEDIR,i); if ((fd = open(buf,O_CREAT | O_TRUNC | O_WRONLY, 0644)) < 0) { perror(buf); return(-1); } close(fd); } } delete_files() { DIR *dirp; struct dirent *dp; char buf[2048]; if ((dirp = opendir(BASEDIR)) == NULL) { perror("opendir"); return (-1); } while ((dp = readdir(dirp)) != NULL) { if (dp->d_name[0] == '.') continue; snprintf(buf,2048,"%s/%s",BASEDIR,dp->d_name); fprintf(stderr,"%s\n",buf); if (unlink(buf) < 0) { perror(buf); return (-1); } /* Workaround */ /* rewinddir(dirp); */ /* End workaround */ } }
State Changed From-To: open->analyzed See also kern/57696. This is a known problem in the nfs code; the ufs code contains code to deal with this situation. Bug peter for more details :-)
Responsible Changed From-To: freebsd-bugs->cel
Responsible Changed From-To: cel->freebsd-bugs Back to the public pool.
State Changed From-To: analyzed->feedback Needs new analysis.
Responsible Changed From-To: freebsd-bugs->rwatson Needs new analysis.
Responsible Changed From-To: rwatson->freebsd-bugs Return to public pool; unfortunately, I don't have time to work on this issue currently.
Responsible Changed From-To: freebsd-bugs->vwe Dear submitter: Do you still see this problem with an actual released version? Over the years someone believed this problem might have gone but it's currently unsure if that's true. this ticket will be closed at the next after-EOL cleanup (scheduled for June) if it is not checked until then. -> track
State Changed From-To: feedback->closed per vwe
This isn't really fixed, it's due to unlink inside readdir loop. https://lists.freebsd.org/pipermail/freebsd-fs/2014-October/020155.html
Duping to Bug 57696 which has better discussion. *** This bug has been marked as a duplicate of bug 57696 ***