Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Feb 2003 02:46:33 +0000
From:      "Clark C. Evans" <cce@clarkevans.com>
To:        freebsd-hackers@freebsd.org
Cc:        tlambert2@mindspring.com
Subject:   Re: cd9660 and fcntl (shared locks)
Message-ID:  <20030212024633.GA75548@doublegemini.com>

next in thread | raw e-mail | index | archive | help
This patch which Terry gave a while back works beautyfully for
my needs and hasn't given me any problems.  I was wondering if 
it could be applied to the main trunk?   I'm asking beacause
maintaining the patch (and a separate build) isn't ideal.  Below
is an updated patch which seems to work well against the current
4.X tree (I haven't tested against 5.X yet).

Clark
P.S. My patch follows Terry's

On Mon, Nov 18, 2002 at 08:19:30PM -0800, Terry Lambert wrote:
| "Clark C. Evans" wrote:
| > When I open a file mounted via cd9660 as O_RDONLY and then flock(fd,LOCK_SH)
| > it returns invalid argument; is there a reason why the cd-rom file
| > system can't just return success here, make flock a no-op that is always
| > successful?  There are many cases where you want general code to use
| > shared locks on files opened for reading to make sure that it doesn't
| > get changed during the read.  This general code should be useable on
| > file systems mounted read only.
| > 
| > Thoughts?  Is there an easy patch?
| 
| FreeBSD implements advisory locking wrong; I've tried to get it
| fixed several times, but no one is interested.
| 
| It looks like someone started to add suport, but then didn't, and
| perpetuated the implementation problem.
| 
| Here is a patch which finishes adding add advisory locking support
| to isofs (wrong way to do it, but only way to do it without changing
| VOP_ADVLOCK semantics).
| 
| -- Terry
| Index: isofs/cd9660/cd9660_vnops.c
| ===================================================================
| RCS file: /cvs/src/sys/isofs/cd9660/cd9660_vnops.c,v
| retrieving revision 1.80
| diff -c -r1.80 cd9660_vnops.c
| *** isofs/cd9660/cd9660_vnops.c	28 Sep 2002 17:14:52 -0000	1.80
| --- isofs/cd9660/cd9660_vnops.c	19 Nov 2002 00:13:27 -0000
| ***************
| *** 53,58 ****
| --- 53,59 ----
|   #include <sys/dirent.h>
|   #include <sys/unistd.h>
|   #include <sys/filio.h>
| + #include <sys/lockf.h>
|   
|   #include <vm/vm.h>
|   #include <vm/vnode_pager.h>
| ***************
| *** 64,69 ****
| --- 65,71 ----
|   
|   static int cd9660_setattr(struct vop_setattr_args *);
|   static int cd9660_access(struct vop_access_args *);
| + static int cd9660_advlock(struct vop_advlock_args *);
|   static int cd9660_getattr(struct vop_getattr_args *);
|   static int cd9660_ioctl(struct vop_ioctl_args *);
|   static int cd9660_pathconf(struct vop_pathconf_args *);
| ***************
| *** 776,787 ****
| --- 778,808 ----
|   }
|   
|   /*
| +  * Advisory record locking support
| +  */
| + static int
| + cd9660_advlock(ap)
| + 	struct vop_advlock_args /* {
| + 		struct vnode *a_vp;
| + 		caddr_t  a_id;
| + 		int  a_op;
| + 		struct flock *a_fl;
| + 		int  a_flags;
| + 	} */ *ap;
| + {
| + 	struct iso_node *ip = VTOI(ap->a_vp);
| + 
| + 	return (lf_advlock(ap, &(ip->i_lockf), ip->i_size));
| + }
| + 
| + /*
|    * Global vfs data structures for cd9660
|    */
|   vop_t **cd9660_vnodeop_p;
|   static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
|   	{ &vop_default_desc,		(vop_t *) vop_defaultop },
|   	{ &vop_access_desc,		(vop_t *) cd9660_access },
| + 	{ &vop_advlock_desc,		(vop_t *) cd9660_advlock },
|   	{ &vop_bmap_desc,		(vop_t *) cd9660_bmap },
|   	{ &vop_cachedlookup_desc,	(vop_t *) cd9660_lookup },
|   	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },


*** cd9660_vnops.c.orig	Tue Feb 11 20:52:05 2003
--- cd9660_vnops.c	Tue Feb 11 20:59:22 2003
***************
*** 52,57 ****
--- 52,58 ----
  #include <sys/dirent.h>
  #include <sys/unistd.h>
  #include <sys/filio.h>
+ #include <sys/lockf.h>
  
  #include <vm/vm.h>
  #include <vm/vm_zone.h>
***************
*** 63,68 ****
--- 64,70 ----
  
  static int cd9660_setattr __P((struct vop_setattr_args *));
  static int cd9660_access __P((struct vop_access_args *));
+ static int cd9660_advlock __P((struct vop_advlock_args *));
  static int cd9660_getattr __P((struct vop_getattr_args *));
  static int cd9660_ioctl __P((struct vop_ioctl_args *));
  static int cd9660_pathconf __P((struct vop_pathconf_args *));
***************
*** 858,869 ****
--- 860,883 ----
  }
  
  /*
+  * Advisory record locking support
+  */
+ static int
+ cd9660_advlock(ap)
+ 	struct vop_advlock_args *ap;
+ {
+ 	struct iso_node *ip = VTOI(ap->a_vp);
+ 	return (lf_advlock(ap, &(ip->i_lockf), ip->i_size));
+ }
+ 
+ /*
   * Global vfs data structures for cd9660
   */
  vop_t **cd9660_vnodeop_p;
  static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
  	{ &vop_default_desc,		(vop_t *) vop_defaultop },
  	{ &vop_access_desc,		(vop_t *) cd9660_access },
+ 	{ &vop_advlock_desc,		(vop_t *) cd9660_advlock },
  	{ &vop_bmap_desc,		(vop_t *) cd9660_bmap },
  	{ &vop_cachedlookup_desc,	(vop_t *) cd9660_lookup },
  	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030212024633.GA75548>