Skip to content

Commit

Permalink
locks: convert posix locks to file_lock_context
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Acked-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Jeff Layton authored and Jeff Layton committed Jan 16, 2015
1 parent 5263e31 commit bd61e0a
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 198 deletions.
58 changes: 26 additions & 32 deletions fs/ceph/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,15 @@ void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
*fcntl_count = 0;
*flock_count = 0;

spin_lock(&inode->i_lock);
for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) {
if (lock->fl_flags & FL_POSIX)
++(*fcntl_count);
}

ctx = inode->i_flctx;
if (ctx) {
spin_lock(&inode->i_lock);
list_for_each_entry(lock, &ctx->flc_posix, fl_list)
++(*fcntl_count);
list_for_each_entry(lock, &ctx->flc_flock, fl_list)
++(*flock_count);
spin_unlock(&inode->i_lock);
}
spin_unlock(&inode->i_lock);
dout("counted %d flock locks and %d fcntl locks",
*flock_count, *fcntl_count);
}
Expand All @@ -279,7 +276,7 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
int num_fcntl_locks, int num_flock_locks)
{
struct file_lock *lock;
struct file_lock_context *ctx;
struct file_lock_context *ctx = inode->i_flctx;
int err = 0;
int seen_fcntl = 0;
int seen_flock = 0;
Expand All @@ -288,34 +285,31 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
dout("encoding %d flock and %d fcntl locks", num_flock_locks,
num_fcntl_locks);

if (!ctx)
return 0;

spin_lock(&inode->i_lock);
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, &flocks[l]);
if (err)
goto fail;
++l;
list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
++seen_fcntl;
if (seen_fcntl > num_fcntl_locks) {
err = -ENOSPC;
goto fail;
}
err = lock_to_ceph_filelock(lock, &flocks[l]);
if (err)
goto fail;
++l;
}

ctx = inode->i_flctx;
if (ctx) {
list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
++seen_flock;
if (seen_flock > num_flock_locks) {
err = -ENOSPC;
goto fail;
}
err = lock_to_ceph_filelock(lock, &flocks[l]);
if (err)
goto fail;
++l;
list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
++seen_flock;
if (seen_flock > num_flock_locks) {
err = -ENOSPC;
goto fail;
}
err = lock_to_ceph_filelock(lock, &flocks[l]);
if (err)
goto fail;
++l;
}
fail:
spin_unlock(&inode->i_lock);
Expand Down
26 changes: 10 additions & 16 deletions fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,11 +1109,6 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
return rc;
}

/* copied from fs/locks.c with a name change */
#define cifs_for_each_lock(inode, lockp) \
for (lockp = &inode->i_flock; *lockp != NULL; \
lockp = &(*lockp)->fl_next)

struct lock_to_push {
struct list_head llist;
__u64 offset;
Expand All @@ -1128,19 +1123,22 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
{
struct inode *inode = cfile->dentry->d_inode;
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
struct file_lock *flock, **before;
unsigned int count = 0, i = 0;
struct file_lock *flock;
struct file_lock_context *flctx = inode->i_flctx;
unsigned int count = 0, i;
int rc = 0, xid, type;
struct list_head locks_to_send, *el;
struct lock_to_push *lck, *tmp;
__u64 length;

xid = get_xid();

if (!flctx)
goto out;

spin_lock(&inode->i_lock);
cifs_for_each_lock(inode, before) {
if ((*before)->fl_flags & FL_POSIX)
count++;
list_for_each(el, &flctx->flc_posix) {
count++;
}
spin_unlock(&inode->i_lock);

Expand All @@ -1151,7 +1149,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
* added to the list while we are holding cinode->lock_sem that
* protects locking operations of this inode.
*/
for (; i < count; i++) {
for (i = 0; i < count; i++) {
lck = kmalloc(sizeof(struct lock_to_push), GFP_KERNEL);
if (!lck) {
rc = -ENOMEM;
Expand All @@ -1162,10 +1160,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)

el = locks_to_send.next;
spin_lock(&inode->i_lock);
cifs_for_each_lock(inode, before) {
flock = *before;
if ((flock->fl_flags & FL_POSIX) == 0)
continue;
list_for_each_entry(flock, &flctx->flc_posix, fl_list) {
if (el == &locks_to_send) {
/*
* The list ended. We don't have enough allocated
Expand All @@ -1185,7 +1180,6 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
lck->length = length;
lck->type = type;
lck->offset = flock->fl_start;
el = el->next;
}
spin_unlock(&inode->i_lock);

Expand Down
20 changes: 13 additions & 7 deletions fs/lockd/svcsubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,15 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
{
struct inode *inode = nlmsvc_file_inode(file);
struct file_lock *fl;
struct file_lock_context *flctx = inode->i_flctx;
struct nlm_host *lockhost;

if (!flctx || list_empty_careful(&flctx->flc_posix))
return 0;
again:
file->f_locks = 0;
spin_lock(&inode->i_lock);
for (fl = inode->i_flock; fl; fl = fl->fl_next) {
list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
if (fl->fl_lmops != &nlmsvc_lock_operations)
continue;

Expand Down Expand Up @@ -223,18 +226,21 @@ nlm_file_inuse(struct nlm_file *file)
{
struct inode *inode = nlmsvc_file_inode(file);
struct file_lock *fl;
struct file_lock_context *flctx = inode->i_flctx;

if (file->f_count || !list_empty(&file->f_blocks) || file->f_shares)
return 1;

spin_lock(&inode->i_lock);
for (fl = inode->i_flock; fl; fl = fl->fl_next) {
if (fl->fl_lmops == &nlmsvc_lock_operations) {
spin_unlock(&inode->i_lock);
return 1;
if (flctx && !list_empty_careful(&flctx->flc_posix)) {
spin_lock(&inode->i_lock);
list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
if (fl->fl_lmops == &nlmsvc_lock_operations) {
spin_unlock(&inode->i_lock);
return 1;
}
}
spin_unlock(&inode->i_lock);
}
spin_unlock(&inode->i_lock);
file->f_locks = 0;
return 0;
}
Expand Down
Loading

0 comments on commit bd61e0a

Please sign in to comment.