Thread: [Libsysio-commit] HEAD: libsysio/include file.h inode.h
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2004-04-28 12:23:27
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31477/include Modified Files: file.h inode.h Log Message: From Sue Kelly; Mike says it shows an unlink, followed by 2 closes, all on the same fd.The second close is getting the assert failure, I guess. We weren't tracking the number of soft references on the inode with file open/close. Hence, it was always 1. When unlink was called, it tries to whack the inode. We've implemented zombie inode code but since there was only one reference, the inode would immediately die. Then, the file close code would try to close it again. However, the inode had already been free'd. Some paranoia in the lower code cleared fields before releasing the memory to protect against just such an event. Voila, instant assertion. Good for us. The fix, of course, is to address the root cause. Inode open/close pairs are now tracked in the file code by referencing and dereferencing the affected inode. Unlink is unchanged. However, now the zombie handling code gets a chance to do it's thing correctly. Index: file.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/file.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -b -B -p -r1.8 -r1.9 --- file.h 6 Feb 2004 20:07:29 -0000 1.8 +++ file.h 28 Apr 2004 12:23:19 -0000 1.9 @@ -64,6 +64,7 @@ struct file { do { \ (fil)->f_ref++; \ assert((fil)->f_ref); \ + I_REF((fil)->f_ino); \ } while (0) /* @@ -71,14 +72,20 @@ struct file { */ #define F_RELE(fil) \ do { \ + struct inode *ino; \ + \ assert((fil)->f_ref); \ (fil)->f_ref--; \ + ino = (fil)->f_ino; \ if (!(fil)->f_ref) \ _sysio_fgone(fil); \ + I_RELE(ino); \ } while (0) /* * Init file record. + * + * NB: Don't forget to take a reference to the inode too! */ #define _SYSIO_FINIT(fil, ino, flags) \ do { \ Index: inode.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/inode.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -w -b -B -p -r1.16 -r1.17 --- inode.h 16 Apr 2004 20:38:34 -0000 1.16 +++ inode.h 28 Apr 2004 12:23:19 -0000 1.17 @@ -177,7 +177,8 @@ struct inode { #define I_RELE(ino) \ do { \ assert((ino)->i_ref); \ - --(ino)->i_ref; \ + if (!--(ino)->i_ref && (ino)->i_zombie) \ + _sysio_i_gone(ino); \ } while (0) /* @@ -187,8 +188,6 @@ struct inode { do { \ _sysio_i_undead(ino); \ I_RELE(ino); \ - if (!(ino)->i_ref) \ - _sysio_i_gone(ino); \ } while (0) /* |
From: Lee W. <lw...@us...> - 2006-05-03 22:31:09
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18135/include Modified Files: file.h inode.h Log Message: Some code cleanup. Support permission (and RO mount) checks in some routines. Added two new tests; test_mkdir and test_mknod. Index: file.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/file.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -w -b -B -p -r1.14 -r1.15 --- file.h 10 Apr 2006 23:25:54 -0000 1.14 +++ file.h 3 May 2006 22:31:04 -0000 1.15 @@ -115,18 +115,15 @@ struct file { /* * Determine if a file may be read/written. * - * Give it the open file table ptr and a character indicating read, 'r', or - * write 'w'. It will return 0 if that access is permitted or -EBADF, if not. + * Given a ptr to an open file table entry and a flag indicating read or + * write return 0 if the file record indicates that the access is permitted + * or -EBADF, if not. */ #define F_CHKRW(_fil, _c) \ - ((_c) == O_RDONLY \ - ? (((_fil)->f_flags & O_RDONLY || (_fil)->f_flags & O_RDWR) \ - ? 0 \ - : -EBADF) \ - : (((_fil)->f_flags & O_WRONLY || (_fil)->f_flags & O_RDWR) \ - ? (IS_RDONLY(NULL, (_fil)->f_ino) ? -EROFS : 0) \ - : -EBADF)) + (((_c) == O_RDONLY && \ + ((_fil)->f_flags & O_RDONLY || (_fil)->f_flags & O_RDWR)) || \ + ((_fil)->f_flags & O_WRONLY || (_fil)->f_flags & O_RDWR)) struct ioctx; Index: inode.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/inode.h,v retrieving revision 1.25 retrieving revision 1.26 diff -u -w -b -B -p -r1.25 -r1.26 --- inode.h 4 Aug 2005 20:17:10 -0000 1.25 +++ inode.h 3 May 2006 22:31:04 -0000 1.26 @@ -325,6 +325,7 @@ struct nameidata { */ #define ND_NOFOLLOW 0x01 /* no follow symlinks */ #define ND_NEGOK 0x02 /* last missing is ok */ +#define ND_NOPERMCHECK 0x04 /* don't check perms */ #ifdef AUTOMOUNT_FILE_NAME #define _ND_INIT_AUTOMOUNT(nd) ((nd)->nd_amcnt = 0) @@ -399,16 +400,10 @@ struct ioctx { } while (0) /* - * Return whether a pnode/inode is on a read-only mount or file system. + * Return whether access to a pnode is read-only. */ -#define IS_RDONLY(pno, ino) \ - ((((struct pnode *)(pno)) && \ - ((((struct pnode *)(pno))->p_mount->mnt_flags & MOUNT_F_RO) || \ - (((struct pnode *)(pno))->p_base->pb_ino && \ - (((struct pnode *)(pno))->p_base->pb_ino->i_fs->fs_flags & \ - FS_F_RO)))) || \ - (((struct inode *)(ino)) && \ - (((struct inode *)(ino))->i_fs->fs_flags & FS_F_RO))) +#define IS_RDONLY(pno) \ + ((pno)->p_mount->mnt_flags & MOUNT_F_RO) extern struct pnode *_sysio_root; @@ -463,7 +458,7 @@ extern int _sysio_path_walk(struct pnode #ifdef AUTOMOUNT_FILE_NAME extern void _sysio_next_component(const char *path, struct qstr *name); #endif -extern int _sysio_permitted(struct inode *ino, int amode); +extern int _sysio_permitted(struct pnode *pno, int amode); extern int _sysio_namei(struct pnode *pno, const char *path, unsigned flags, @@ -487,3 +482,5 @@ extern int _sysio_ioctx_done(struct ioct extern ssize_t _sysio_ioctx_wait(struct ioctx *ioctx); extern void _sysio_ioctx_complete(struct ioctx *ioctx); extern int _sysio_open(struct pnode *pno, int flags, mode_t mode); +extern int _sysio_mkdir(struct pnode *where, mode_t mode); +extern int _sysio_mknod(struct pnode *where, mode_t mode, dev_t dev); |