aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ceph/locks.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ceph/locks.c')
-rw-r--r--fs/ceph/locks.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
index c35c5c614e38..06ea5cd05cd9 100644
--- a/fs/ceph/locks.c
+++ b/fs/ceph/locks.c
@@ -239,23 +239,21 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
239 return err; 239 return err;
240} 240}
241 241
242/** 242/*
243 * Must be called with lock_flocks() already held. Fills in the passed 243 * Fills in the passed counter variables, so you can prepare pagelist metadata
244 * counter variables, so you can prepare pagelist metadata before calling 244 * before calling ceph_encode_locks.
245 * ceph_encode_locks.
246 */ 245 */
247void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count) 246void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
248{ 247{
249 struct file_lock *lock; 248 struct file_lock_context *ctx;
250 249
251 *fcntl_count = 0; 250 *fcntl_count = 0;
252 *flock_count = 0; 251 *flock_count = 0;
253 252
254 for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) { 253 ctx = inode->i_flctx;
255 if (lock->fl_flags & FL_POSIX) 254 if (ctx) {
256 ++(*fcntl_count); 255 *fcntl_count = ctx->flc_posix_cnt;
257 else if (lock->fl_flags & FL_FLOCK) 256 *flock_count = ctx->flc_flock_cnt;
258 ++(*flock_count);
259 } 257 }
260 dout("counted %d flock locks and %d fcntl locks", 258 dout("counted %d flock locks and %d fcntl locks",
261 *flock_count, *fcntl_count); 259 *flock_count, *fcntl_count);
@@ -271,6 +269,7 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
271 int num_fcntl_locks, int num_flock_locks) 269 int num_fcntl_locks, int num_flock_locks)
272{ 270{
273 struct file_lock *lock; 271 struct file_lock *lock;
272 struct file_lock_context *ctx = inode->i_flctx;
274 int err = 0; 273 int err = 0;
275 int seen_fcntl = 0; 274 int seen_fcntl = 0;
276 int seen_flock = 0; 275 int seen_flock = 0;
@@ -279,33 +278,34 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
279 dout("encoding %d flock and %d fcntl locks", num_flock_locks, 278 dout("encoding %d flock and %d fcntl locks", num_flock_locks,
280 num_fcntl_locks); 279 num_fcntl_locks);
281 280
282 for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) { 281 if (!ctx)
283 if (lock->fl_flags & FL_POSIX) { 282 return 0;
284 ++seen_fcntl; 283
285 if (seen_fcntl > num_fcntl_locks) { 284 spin_lock(&ctx->flc_lock);
286 err = -ENOSPC; 285 list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
287 goto fail; 286 ++seen_fcntl;
288 } 287 if (seen_fcntl > num_fcntl_locks) {
289 err = lock_to_ceph_filelock(lock, &flocks[l]); 288 err = -ENOSPC;
290 if (err) 289 goto fail;
291 goto fail;
292 ++l;
293 } 290 }
291 err = lock_to_ceph_filelock(lock, &flocks[l]);
292 if (err)
293 goto fail;
294 ++l;
294 } 295 }
295 for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) { 296 list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
296 if (lock->fl_flags & FL_FLOCK) { 297 ++seen_flock;
297 ++seen_flock; 298 if (seen_flock > num_flock_locks) {
298 if (seen_flock > num_flock_locks) { 299 err = -ENOSPC;
299 err = -ENOSPC; 300 goto fail;
300 goto fail;
301 }
302 err = lock_to_ceph_filelock(lock, &flocks[l]);
303 if (err)
304 goto fail;
305 ++l;
306 } 301 }
302 err = lock_to_ceph_filelock(lock, &flocks[l]);
303 if (err)
304 goto fail;
305 ++l;
307 } 306 }
308fail: 307fail:
308 spin_unlock(&ctx->flc_lock);
309 return err; 309 return err;
310} 310}
311 311