Fix 64-bit locking code in 2.4.10-preX
Subsystems (4)
PATCH 1/1 Fix 64-bit locking code in 2.4.10-preX
Linus,
The following constitutes a slight rewrite of a patch that has been
sent to you earlier by H.J.
It fixes the locking code so that it conforms to the Single UNIX
specs. According to the latter, we need to return -EOVERFLOW rather than -EINVAL whenever an offset overflows.
In addition, the patch ensures that lockd and the NFS client both
recognize the (G|S)ETLK64 locking commands on 32-bit architectures.
Finally, a small fix to the lockd xdr code. We need to zero unused
bytes in NFS filehandles as the comparisons all assume this.
Cheers,
Trond
fs/lockd/clntproc.c +9 -10
@@ -142,7 +142,7 @@/* If we're cleaning up locks because the process is exiting, * perform the RPC call asynchronously. */ -if ((cmd ==F_SETLK || cmd ==F_SETLKW ) +if ((IS_SETLK (cmd) ||IS_SETLKW (cmd)) && fl->fl_type ==F_UNLCK && (current->flags &PF_EXITING )) {sigfillset (¤t->blocked);/* Mask all signals */
@@ -166,17 +166,16 @@/* Set up the argument struct */ nlmclnt_setlockargs (call, fl); -if (cmd ==F_GETLK ) { +if (IS_SETLK (cmd) ||IS_SETLKW (cmd)) { +if (fl->fl_type !=F_UNLCK ) { + call->a_args.block =IS_SETLKW (cmd) ?1 :0 ; + status =nlmclnt_lock (call, fl); + }else + status =nlmclnt_unlock (call, fl); + }else if (IS_GETLK (cmd)) status =nlmclnt_test (call, fl); - }else if ((cmd ==F_SETLK || cmd ==F_SETLKW ) - && fl->fl_type ==F_UNLCK ) { - status =nlmclnt_unlock (call, fl); - }else if (cmd ==F_SETLK || cmd ==F_SETLKW ) { - call->a_args.block = (cmd ==F_SETLKW )?1 :0 ; - status =nlmclnt_lock (call, fl); - }else { +else status = -EINVAL ; - }if (status <0 && (call->a_flags &RPC_TASK_ASYNC ))kfree (call);
fs/lockd/xdr.c +1 -0
@@ -91,6 +91,7 @@return NULL ; } f->size =NFS2_FHSIZE ; +memset (f->data,0 ,sizeof (f->data));memcpy (f->data, p,NFS2_FHSIZE );return p +XDR_QUADLEN (NFS2_FHSIZE ); }
fs/locks.c +21 -22
108 lines not on this page · raw message
fs/nfs/file.c +2 -2
@@ -264,7 +264,7 @@/* Fake OK code if mounted without NLM support */ if (NFS_SERVER (inode)->flags &NFS_MOUNT_NONLM ) { -if (cmd ==F_GETLK ) +if (IS_GETLK (cmd)) status =LOCK_USE_CLNT ; goto out_ok; }
@@ -304,7 +304,7 @@* This makes locking act as a cache coherency point. */ out_ok: -if ((cmd ==F_SETLK || cmd ==F_SETLKW ) && fl->fl_type !=F_UNLCK ) { +if ((IS_SETLK (cmd) ||IS_SETLKW (cmd)) && fl->fl_type !=F_UNLCK ) {filemap_fdatasync (inode->i_mapping);down (&inode->i_sem);nfs_wb_all (inode);/* we may have slept */
include/linux/fcntl.h +24 -0
@@ -23,4 +23,28 @@#define DN_ATTRIB 0x00000020/* File changed attibutes */ #define DN_MULTISHOT 0x80000000/* Don't remove notifier */ +#ifdef __KERNEL__ + +#if BITS_PER_LONG ==32 +#define IS_GETLK32 (cmd) ((cmd) == F_GETLK) +#define IS_SETLK32 (cmd) ((cmd) == F_SETLK) +#define IS_SETLKW32 (cmd) ((cmd) == F_SETLKW) +#define IS_GETLK64 (cmd) ((cmd) == F_GETLK64) +#define IS_SETLK64 (cmd) ((cmd) == F_SETLK64) +#define IS_SETLKW64 (cmd) ((cmd) == F_SETLKW64) +#else +#define IS_GETLK32 (cmd) (0) +#define IS_SETLK32 (cmd) (0) +#define IS_SETLKW32 (cmd) (0) +#define IS_GETLK64 (cmd) ((cmd) == F_GETLK) +#define IS_SETLK64 (cmd) ((cmd) == F_SETLK) +#define IS_SETLKW64 (cmd) ((cmd) == F_SETLKW) +#endif /* BITS_PER_LONG == 32 */ + +#define IS_GETLK (cmd) (IS_GETLK32(cmd) || IS_GETLK64(cmd)) +#define IS_SETLK (cmd) (IS_SETLK32(cmd) || IS_SETLK64(cmd)) +#define IS_SETLKW (cmd) (IS_SETLKW32(cmd) || IS_SETLKW64(cmd)) + +#endif /* __KERNEL__ */ +#endif