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 | struct nlmsvc_binding { | 27 | struct nlmsvc_binding { |
| 28 | __be32 (*fopen)(struct svc_rqst *, | 28 | __be32 (*fopen)(struct svc_rqst *, |
| 29 | struct nfs_fh *, | 29 | struct nfs_fh *, |
| 30 | struct file **); | 30 | struct file **, |
| 31 | int mode); | ||
| 31 | void (*fclose)(struct file *); | 32 | void (*fclose)(struct file *); |
| 32 | }; | 33 | }; |
| 33 | 34 | ||
| @@ -10,6 +10,8 @@ · 9 unmodified lines | |||
| 10 | #ifndef LINUX_LOCKD_LOCKD_H | 10 | #ifndef LINUX_LOCKD_LOCKD_H |
| 11 | #define LINUX_LOCKD_LOCKD_H | 11 | #define LINUX_LOCKD_LOCKD_H |
| 12 | 12 | ||
| 13 | /* XXX: a lot of this should really be under fs/lockd. */ | ||
| 14 | |||
| 13 | #include <linux/in.h> | 15 | #include <linux/in.h> |
| 14 | #include <linux/in6.h> | 16 | #include <linux/in6.h> |
| 15 | #include <net/ipv6.h> | 17 | #include <net/ipv6.h> |
| @@ -154,7 +156,8 @@ struct nlm_rqst { · 138 unmodified lines | |||
| 154 | struct nlm_file { | 156 | struct nlm_file { |
| 155 | struct hlist_node f_list; /* linked list */ | 157 | struct hlist_node f_list; /* linked list */ |
| 156 | struct nfs_fh f_handle; /* NFS file handle */ | 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 | struct nlm_share * f_shares; /* DOS shares */ | 161 | struct nlm_share * f_shares; /* DOS shares */ |
| 159 | struct list_head f_blocks; /* blocked locks */ | 162 | struct list_head f_blocks; /* blocked locks */ |
| 160 | unsigned int f_locks; /* guesstimate # of locks */ | 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 | * Server-side lock handling | 271 | * Server-side lock handling |
| 269 | */ | 272 | */ |
| 273 | int lock_to_openmode(struct file_lock *); | ||
| 270 | __be32 nlmsvc_lock(struct svc_rqst *, struct nlm_file *, | 274 | __be32 nlmsvc_lock(struct svc_rqst *, struct nlm_file *, |
| 271 | struct nlm_host *, struct nlm_lock *, int, | 275 | struct nlm_host *, struct nlm_lock *, int, |
| 272 | struct nlm_cookie *, int); | 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 | static inline struct inode *nlmsvc_file_inode(struct nlm_file *file) | 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 | static inline int __nlm_privileged_request4(const struct sockaddr *sap) | 312 | static inline int __nlm_privileged_request4(const struct sockaddr *sap) |