diff options
author | Jeff Layton <jlayton@primarydata.com> | 2015-01-16 15:05:55 -0500 |
---|---|---|
committer | Jeff Layton <jeff.layton@primarydata.com> | 2015-01-16 15:09:25 -0500 |
commit | 5263e31e452fb84138b9bee061d5c06c0f359fea (patch) | |
tree | 68726ce860d2c824f605e6ec3f2adc9187d6dc86 /fs/nfs/write.c | |
parent | c362781cadd37858c3d8f5d18b1e9957d4671298 (diff) |
locks: move flock locks to file_lock_context
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/nfs/write.c')
-rw-r--r-- | fs/nfs/write.c | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index af3af685a9e3..e072aeb34195 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c | |||
@@ -1113,6 +1113,11 @@ int nfs_flush_incompatible(struct file *file, struct page *page) | |||
1113 | do_flush |= l_ctx->lockowner.l_owner != current->files | 1113 | do_flush |= l_ctx->lockowner.l_owner != current->files |
1114 | || l_ctx->lockowner.l_pid != current->tgid; | 1114 | || l_ctx->lockowner.l_pid != current->tgid; |
1115 | } | 1115 | } |
1116 | if (l_ctx && ctx->dentry->d_inode->i_flctx && | ||
1117 | !list_empty_careful(&ctx->dentry->d_inode->i_flctx->flc_flock)) { | ||
1118 | do_flush |= l_ctx->lockowner.l_owner != current->files | ||
1119 | || l_ctx->lockowner.l_pid != current->tgid; | ||
1120 | } | ||
1116 | nfs_release_request(req); | 1121 | nfs_release_request(req); |
1117 | if (!do_flush) | 1122 | if (!do_flush) |
1118 | return 0; | 1123 | return 0; |
@@ -1170,6 +1175,13 @@ out: | |||
1170 | return PageUptodate(page) != 0; | 1175 | return PageUptodate(page) != 0; |
1171 | } | 1176 | } |
1172 | 1177 | ||
1178 | static bool | ||
1179 | is_whole_file_wrlock(struct file_lock *fl) | ||
1180 | { | ||
1181 | return fl->fl_start == 0 && fl->fl_end == OFFSET_MAX && | ||
1182 | fl->fl_type == F_WRLCK; | ||
1183 | } | ||
1184 | |||
1173 | /* If we know the page is up to date, and we're not using byte range locks (or | 1185 | /* If we know the page is up to date, and we're not using byte range locks (or |
1174 | * if we have the whole file locked for writing), it may be more efficient to | 1186 | * if we have the whole file locked for writing), it may be more efficient to |
1175 | * extend the write to cover the entire page in order to avoid fragmentation | 1187 | * extend the write to cover the entire page in order to avoid fragmentation |
@@ -1180,17 +1192,38 @@ out: | |||
1180 | */ | 1192 | */ |
1181 | static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode) | 1193 | static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode) |
1182 | { | 1194 | { |
1195 | int ret; | ||
1196 | struct file_lock_context *flctx = inode->i_flctx; | ||
1197 | struct file_lock *fl; | ||
1198 | |||
1183 | if (file->f_flags & O_DSYNC) | 1199 | if (file->f_flags & O_DSYNC) |
1184 | return 0; | 1200 | return 0; |
1185 | if (!nfs_write_pageuptodate(page, inode)) | 1201 | if (!nfs_write_pageuptodate(page, inode)) |
1186 | return 0; | 1202 | return 0; |
1187 | if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE)) | 1203 | if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE)) |
1188 | return 1; | 1204 | return 1; |
1189 | if (inode->i_flock == NULL || (inode->i_flock->fl_start == 0 && | 1205 | if (!inode->i_flock && !flctx) |
1190 | inode->i_flock->fl_end == OFFSET_MAX && | 1206 | return 0; |
1191 | inode->i_flock->fl_type != F_RDLCK)) | 1207 | |
1192 | return 1; | 1208 | /* Check to see if there are whole file write locks */ |
1193 | return 0; | 1209 | spin_lock(&inode->i_lock); |
1210 | ret = 0; | ||
1211 | |||
1212 | fl = inode->i_flock; | ||
1213 | if (fl && is_whole_file_wrlock(fl)) { | ||
1214 | ret = 1; | ||
1215 | goto out; | ||
1216 | } | ||
1217 | |||
1218 | if (!list_empty(&flctx->flc_flock)) { | ||
1219 | fl = list_first_entry(&flctx->flc_flock, struct file_lock, | ||
1220 | fl_list); | ||
1221 | if (fl->fl_type == F_WRLCK) | ||
1222 | ret = 1; | ||
1223 | } | ||
1224 | out: | ||
1225 | spin_unlock(&inode->i_lock); | ||
1226 | return ret; | ||
1194 | } | 1227 | } |
1195 | 1228 | ||
1196 | /* | 1229 | /* |