Skip to content

Commit

Permalink
CIFS: Move brlock code to ops struct
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org>
  • Loading branch information
Pavel Shilovsky authored and Steve French committed Sep 25, 2012
1 parent f45d341 commit d39a4f7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
8 changes: 8 additions & 0 deletions fs/cifs/cifsglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ struct smb_version_operations {
/* query remote filesystem */
int (*queryfs)(const unsigned int, struct cifs_tcon *,
struct kstatfs *);
/* send mandatory brlock to the server */
int (*mand_lock)(const unsigned int, struct cifsFileInfo *, __u64,
__u64, __u32, int, int, bool);
/* unlock range of mandatory locks */
int (*mand_unlock_range)(struct cifsFileInfo *, struct file_lock *,
const unsigned int);
/* push brlocks from the cache to the server */
int (*push_mand_locks)(struct cifsFileInfo *);
};

struct smb_version_values {
Expand Down
3 changes: 3 additions & 0 deletions fs/cifs/cifsproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ extern u64 cifs_UnixTimeToNT(struct timespec);
extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time,
int offset);
extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock);
extern int cifs_unlock_range(struct cifsFileInfo *cfile,
struct file_lock *flock, const unsigned int xid);
extern int cifs_push_mandatory_locks(struct cifsFileInfo *cfile);

extern struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid,
struct file *file,
Expand Down
42 changes: 17 additions & 25 deletions fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ cifs_posix_lock_set(struct file *file, struct file_lock *flock)
return rc;
}

static int
int
cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
{
unsigned int xid;
Expand Down Expand Up @@ -1111,7 +1111,7 @@ cifs_push_locks(struct cifsFileInfo *cfile)
((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
return cifs_push_posix_locks(cfile);

return cifs_push_mandatory_locks(cfile);
return tcon->ses->server->ops->push_mand_locks(cfile);
}

static void
Expand Down Expand Up @@ -1161,15 +1161,6 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
cFYI(1, "Unknown type of lock");
}

static int
cifs_mandatory_lock(unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
__u64 length, __u32 type, int lock, int unlock, bool wait)
{
return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->fid.netfid,
current->tgid, length, offset, unlock, lock,
(__u8)type, wait, 0);
}

static int
cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
bool wait_flag, bool posix_lck, unsigned int xid)
Expand Down Expand Up @@ -1203,11 +1194,11 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
return rc;

/* BB we could chain these into one lock request BB */
rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, type,
1, 0, false);
rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, type,
1, 0, false);
if (rc == 0) {
rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
type, 0, 1, false);
rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
type, 0, 1, false);
flock->fl_type = F_UNLCK;
if (rc != 0)
cERROR(1, "Error unlocking previously locked "
Expand All @@ -1220,13 +1211,14 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
return 0;
}

rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
type | server->vals->shared_lock_type, 1, 0,
false);
type &= ~server->vals->exclusive_lock_type;

rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
type | server->vals->shared_lock_type,
1, 0, false);
if (rc == 0) {
rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
type | server->vals->shared_lock_type,
0, 1, false);
rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
type | server->vals->shared_lock_type, 0, 1, false);
flock->fl_type = F_RDLCK;
if (rc != 0)
cERROR(1, "Error unlocking previously locked "
Expand Down Expand Up @@ -1256,7 +1248,7 @@ cifs_free_llist(struct list_head *llist)
}
}

static int
int
cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
unsigned int xid)
{
Expand Down Expand Up @@ -1408,16 +1400,16 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
if (rc <= 0)
goto out;

rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
type, 1, 0, wait_flag);
rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
type, 1, 0, wait_flag);
if (rc) {
kfree(lock);
goto out;
}

cifs_lock_add(cfile, lock);
} else if (unlock)
rc = cifs_unlock_range(cfile, flock, xid);
rc = server->ops->mand_unlock_range(cfile, flock, xid);

out:
if (flock->fl_flags & FL_POSIX)
Expand Down
12 changes: 12 additions & 0 deletions fs/cifs/smb1ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,15 @@ cifs_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
return rc;
}

static int
cifs_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
__u64 length, __u32 type, int lock, int unlock, bool wait)
{
return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->fid.netfid,
current->tgid, length, offset, unlock, lock,
(__u8)type, wait, 0);
}

struct smb_version_operations smb1_operations = {
.send_cancel = send_nt_cancel,
.compare_fids = cifs_compare_fids,
Expand Down Expand Up @@ -960,6 +969,9 @@ struct smb_version_operations smb1_operations = {
.calc_smb_size = smbCalcSize,
.oplock_response = cifs_oplock_response,
.queryfs = cifs_queryfs,
.mand_lock = cifs_mand_lock,
.mand_unlock_range = cifs_unlock_range,
.push_mand_locks = cifs_push_mandatory_locks,
};

struct smb_version_values smb1_values = {
Expand Down

0 comments on commit d39a4f7

Please sign in to comment.