Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 211606
b: refs/heads/master
c: fca4451
h: refs/heads/master
v: v3
  • Loading branch information
Greg Farnum authored and Sage Weil committed Oct 20, 2010
1 parent dbaec33 commit 45ccc6c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ac0b74d8a1ced8ea86147467daf06b15b130dd94
refs/heads/master: fca4451acfdcf894154e4809529ca28a09db88ff
17 changes: 15 additions & 2 deletions trunk/fs/ceph/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,18 @@ void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
* Encode the flock and fcntl locks for the given inode into the pagelist.
* Format is: #fcntl locks, sequential fcntl locks, #flock locks,
* sequential flock locks.
* Must be called with BLK already held, and the lock numbers should have
* been gathered under the same lock holding window.
* Must be called with lock_flocks() already held.
* If we encounter more of a specific lock type than expected,
* we return the value 1.
*/
int ceph_encode_locks(struct inode *inode, struct ceph_pagelist *pagelist,
int num_fcntl_locks, int num_flock_locks)
{
struct file_lock *lock;
struct ceph_filelock cephlock;
int err = 0;
int seen_fcntl = 0;
int seen_flock = 0;

dout("encoding %d flock and %d fcntl locks", num_flock_locks,
num_fcntl_locks);
Expand All @@ -198,6 +201,11 @@ int ceph_encode_locks(struct inode *inode, struct ceph_pagelist *pagelist,
goto fail;
for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) {
if (lock->fl_flags & FL_POSIX) {
++seen_fcntl;
if (seen_fcntl > num_fcntl_locks) {
err = -ENOSPC;
goto fail;
}
err = lock_to_ceph_filelock(lock, &cephlock);
if (err)
goto fail;
Expand All @@ -213,6 +221,11 @@ int ceph_encode_locks(struct inode *inode, struct ceph_pagelist *pagelist,
goto fail;
for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) {
if (lock->fl_flags & FL_FLOCK) {
++seen_flock;
if (seen_flock > num_flock_locks) {
err = -ENOSPC;
goto fail;
}
err = lock_to_ceph_filelock(lock, &cephlock);
if (err)
goto fail;
Expand Down
42 changes: 29 additions & 13 deletions trunk/fs/ceph/mds_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2365,19 +2365,35 @@ static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,

if (recon_state->flock) {
int num_fcntl_locks, num_flock_locks;

lock_kernel();
ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks);
rec.v2.flock_len = (2*sizeof(u32) +
(num_fcntl_locks+num_flock_locks) *
sizeof(struct ceph_filelock));

err = ceph_pagelist_append(pagelist, &rec, reclen);
if (!err)
err = ceph_encode_locks(inode, pagelist,
num_fcntl_locks,
num_flock_locks);
unlock_kernel();
struct ceph_pagelist_cursor trunc_point;

ceph_pagelist_set_cursor(pagelist, &trunc_point);
do {
lock_kernel();
ceph_count_locks(inode, &num_fcntl_locks,
&num_flock_locks);
rec.v2.flock_len = (2*sizeof(u32) +
(num_fcntl_locks+num_flock_locks) *
sizeof(struct ceph_filelock));
unlock_kernel();

/* pre-alloc pagelist */
ceph_pagelist_truncate(pagelist, &trunc_point);
err = ceph_pagelist_append(pagelist, &rec, reclen);
if (!err)
err = ceph_pagelist_reserve(pagelist,
rec.v2.flock_len);

/* encode locks */
if (!err) {
lock_kernel();
err = ceph_encode_locks(inode,
pagelist,
num_fcntl_locks,
num_flock_locks);
unlock_kernel();
}
} while (err == -ENOSPC);
} else {
err = ceph_pagelist_append(pagelist, &rec, reclen);
}
Expand Down

0 comments on commit 45ccc6c

Please sign in to comment.