We shouldn't really be using a read-only file descriptor to take a write lock. Most filesystems will put up with it. But NFS, for example, won't.
Showing the changes to include/linux/lockd (2 of 7 files). Show all
Unified · Split
| @@ -27,7 +27,8 @@ struct rpc_task; · 26 unmodified lines | ||
| 27 | 27 | struct nlmsvc_binding { |
| 28 | 28 | __be32 (*fopen)(struct svc_rqst *, |
| 29 | 29 | struct nfs_fh *, |
| 30 | − struct file **); | |
| 30 | + struct file **, | |
| 31 | + int mode); | |
| 31 | 32 | void (*fclose)(struct file *); |
| 32 | 33 | }; |
| 33 | 34 | |
| @@ -10,6 +10,8 @@ · 9 unmodified lines | ||
| 10 | 10 | #ifndef LINUX_LOCKD_LOCKD_H |
| 11 | 11 | #define LINUX_LOCKD_LOCKD_H |
| 12 | 12 | |
| 13 | +/* XXX: a lot of this should really be under fs/lockd. */ | |
| 14 | + | |
| 13 | 15 | #include <linux/in.h> |
| 14 | 16 | #include <linux/in6.h> |
| 15 | 17 | #include <net/ipv6.h> |
| @@ -154,7 +156,8 @@ struct nlm_rqst { · 138 unmodified lines | ||
| 154 | 156 | struct nlm_file { |
| 155 | 157 | struct hlist_node f_list; /* linked list */ |
| 156 | 158 | struct nfs_fh f_handle; /* NFS file handle */ |
| 157 | − struct file * f_file; /* VFS file pointer */ | |
| 159 | + struct file * f_file[2]; /* VFS file pointers, | |
| 160 | + indexed by O_ flags */ | |
| 158 | 161 | struct nlm_share * f_shares; /* DOS shares */ |
| 159 | 162 | struct list_head f_blocks; /* blocked locks */ |
| 160 | 163 | unsigned int f_locks; /* guesstimate # of locks */ |
| @@ -267,6 +270,7 @@ typedef int (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref); · 106 unmodified lines | ||
| 267 | 270 | /* |
| 268 | 271 | * Server-side lock handling |
| 269 | 272 | */ |
| 273 | +int lock_to_openmode(struct file_lock *); | |
| 270 | 274 | __be32 nlmsvc_lock(struct svc_rqst *, struct nlm_file *, |
| 271 | 275 | struct nlm_host *, struct nlm_lock *, int, |
| 272 | 276 | struct nlm_cookie *, int); |
| @@ -301,7 +305,8 @@ int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr); · 28 unmodified lines | ||
| 301 | 305 | |
| 302 | 306 | static inline struct inode *nlmsvc_file_inode(struct nlm_file *file) |
| 303 | 307 | { |
| 304 | − return locks_inode(file->f_file); | |
| 308 | + return locks_inode(file->f_file[O_RDONLY] ? | |
| 309 | + file->f_file[O_RDONLY] : file->f_file[O_WRONLY]); | |
| 305 | 310 | } |
| 306 | 311 | |
| 307 | 312 | static inline int __nlm_privileged_request4(const struct sockaddr *sap) |