Thread: [Libsysio-commit] HEAD: libsysio/src file_hack.c
Brought to you by:
lward
From: MeiJia <me...@us...> - 2004-05-25 05:57:18
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19427/src Modified Files: file_hack.c Log Message: hack code for lustre. Index: file_hack.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/file_hack.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -b -B -p -r1.1 -r1.2 --- file_hack.c 20 May 2004 19:31:48 -0000 1.1 +++ file_hack.c 25 May 2004 05:56:58 -0000 1.2 @@ -393,7 +393,10 @@ _sysio_fd_close_all() * Close all open descriptors. */ _sysio_oftable_close_all(&_sysio_oftab[OFTAB_VIRTUAL]); + /* XXX see liblustre/llite_lib.c for explaination */ +#if 0 _sysio_oftable_close_all(&_sysio_oftab[OFTAB_NATIVE]); +#endif /* * Release current working directory. |
From: MeiJia <me...@us...> - 2004-07-28 06:39:29
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16504/src Modified Files: file_hack.c Log Message: lustre hack code to follow the changes of sysio_fd_set() Index: file_hack.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/file_hack.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -b -B -p -r1.4 -r1.5 --- file_hack.c 27 Jul 2004 15:00:43 -0000 1.4 +++ file_hack.c 28 Jul 2004 06:39:21 -0000 1.5 @@ -203,24 +203,27 @@ _sysio_fd_shutdown() #endif /* - * Find a free slot in the open files table. - * target < 0: any free slot - * target >= 0: get slot [target] + * Find a free slot in the open files table which >= @low + * low < 0 means any */ static int -find_free_fildes(oftab_t *oftab, int target) +find_free_fildes(oftab_t *oftab, int low) { int n; int err; struct file **filp; - if (target < 0) { - for (n = 0, filp = oftab->table; + if (low < 0) + low = oftab->offset; + + n = low - oftab->offset; + if (n < 0) + return -ENFILE; + + for (filp = oftab->table + n; n < oftab->size && *filp; n++, filp++) ; - } else - n = target - oftab->offset; if (n >= oftab->size) { err = fd_grow(oftab, n); @@ -230,18 +233,6 @@ find_free_fildes(oftab_t *oftab, int tar assert(!*filp); } -#ifdef HAVE_LUSTRE_HACK - /* FIXME sometimes we could intercept open/socket to create - * a fd, but missing close()? currently we have this problem - * with resolv lib. as a workaround simply destroy the file - * struct here. - */ - if (oftab->table[n]) { - free(oftab->table[n]); - oftab->table[n] = NULL; - } -#endif - return oftab->offset + n; } @@ -298,35 +289,55 @@ _sysio_fd_close(int fd) } /* - * Associate open file record with given file descriptor or any available - * file descriptor if less than zero. + * Associate open file record with given file descriptor (if forced), or any + * available file descriptor if less than zero, or any available descriptor + * greater than or equal to the given one if not forced. */ int -_sysio_fd_set(struct file *fil, int fd) +_sysio_fd_set(struct file *fil, int fd, int force) { int err; struct file *ofil; oftab_t *oftab; + if (force && fd < 0) + abort(); + init_oftab(); oftab = select_oftab(fd); /* - * New fd < 0 => any available descriptor. + * Search for a free descriptor if needed. */ + if (!force) { fd = find_free_fildes(oftab, fd); if (fd < 0) return fd; + } - assert(fd < oftab->offset + oftab->size); + if (fd - oftab->offset >= oftab->size) { + err = fd_grow(oftab, fd - oftab->offset); + if (err) + return err; + } /* * Remember old. */ ofil = __sysio_fd_get(fd, 1); - if (ofil) + if (ofil) { + /* FIXME sometimes we could intercept open/socket to create + * a fd, but missing close()? currently we have this problem + * with resolv lib. as a workaround simply destroy the file + * struct here. And this hack will break the behavior of + * DUPFD. + */ + if (fd >= 0 && oftab == &_sysio_oftab[0]) + free(ofil); + else F_RELE(ofil); + } oftab->table[fd - oftab->offset] = fil; @@ -337,10 +348,12 @@ _sysio_fd_set(struct file *fil, int fd) * Duplicate old file descriptor. * * If the new file descriptor is less than zero, the new file descriptor - * is chosen freely. + * is chosen freely. Otherwise, choose an available descriptor greater + * than or equal to the new, if not forced. Otherwise, if forced, (re)use + * the new. */ int -_sysio_fd_dup2(int oldfd, int newfd) +_sysio_fd_dup(int oldfd, int newfd, int force) { struct file *fil; int fd; @@ -358,7 +371,7 @@ _sysio_fd_dup2(int oldfd, int newfd) if (select_oftab(oldfd) != select_oftab(newfd)) return -EINVAL; - fd = _sysio_fd_set(fil, newfd); + fd = _sysio_fd_set(fil, newfd, force); if (fd >= 0) F_REF(fil); return fd; |
From: Lee W. <lw...@us...> - 2005-06-16 20:37:01
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24966 Modified Files: file_hack.c Log Message: Must return the file descriptor, not simple 0, when new == old. Index: file_hack.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/file_hack.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -w -b -B -p -r1.6 -r1.7 --- file_hack.c 21 Sep 2004 16:18:30 -0000 1.6 +++ file_hack.c 16 Jun 2005 20:36:48 -0000 1.7 @@ -362,7 +362,7 @@ _sysio_fd_dup(int oldfd, int newfd, int init_oftab(); if (oldfd == newfd) - return 0; + return newfd; fil = _sysio_fd_find(oldfd); if (!fil) |
From: Lee W. <lw...@us...> - 2006-01-04 13:16:28
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv890 Modified Files: file_hack.c Log Message: File new/gone routines weren't referencing and releasing, respectively, the associated inode. Fixed. From Oleg Drokin at Cluster FS. Index: file_hack.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/file_hack.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -w -b -B -p -r1.9 -r1.10 --- file_hack.c 16 Jun 2005 21:14:52 -0000 1.9 +++ file_hack.c 4 Jan 2006 13:16:18 -0000 1.10 @@ -107,6 +107,7 @@ _sysio_fnew(struct inode *ino, int flags _SYSIO_FINIT(fil, ino, flags); F_REF(fil); + I_REF(ino); return fil; } @@ -122,6 +123,7 @@ _sysio_fgone(struct file *fil) assert(!fil->f_ref); assert(fil->f_ino); err = (*fil->f_ino->i_ops.inop_close)(fil->f_ino); + I_RELE(fil->f_ino); assert(!err); free(fil); } |