Skip to contentSkip to conversation

cifs: stuff the fl_owner into "pid" field in the lock request

PATCH In review Jeff Layton 3 participants 3 messages May 24, 2016 – May 25, 2016 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: stuff the fl_owner into "pid" field in the lock request

Right now, we send the tgid cross the wire. What we really want to send though is a hashed fl_owner_t since samba treats this field as a generic lockowner.

It turns out that because we enforce and release locks locally before they are ever sent to the server, this patch makes no difference in behavior. Still, setting OFD locks on the server using the process pid seems wrong, so I think this patch still makes sense.

---
 fs/cifs/cifsfs.c   |  3 +++
 fs/cifs/cifsglob.h |  1 +
 fs/cifs/file.c     | 14 +++++++++++---
 3 files changed, 15 insertions(+), 3 deletions(-)
fs/cifs/cifsfs.c +3 -0
index 08fa36e5b2bc..1ef5b8aee878 100644
@@ -87,6 +87,7 @@ extern mempool_t *cifs_req_poolp;
 extern mempool_t *cifs_mid_poolp;
 
 struct workqueue_struct	*cifsiod_wq;
+__u32 cifs_lock_secret;
 
 /*
  * Bumps refcount for cifs super block.
@@ -1271,6 +1272,8 @@ init_cifs(void)
 	spin_lock_init(&cifs_file_list_lock);
 	spin_lock_init(&GlobalMid_Lock);
 
+	get_random_bytes(&cifs_lock_secret, sizeof(cifs_lock_secret));
+
 	if (cifs_max_pending < 2) {
 		cifs_max_pending = 2;
 		cifs_dbg(FYI, "cifs_max_pending set to min of 2\n");
fs/cifs/cifsglob.h +1 -0
index bba106cdc43c..8f1d8c1e72be 100644
@@ -1619,6 +1619,7 @@ void cifs_oplock_break(struct work_struct *work);
 
 extern const struct slow_work_ops cifs_oplock_break_ops;
 extern struct workqueue_struct *cifsiod_wq;
+extern __u32 cifs_lock_secret;
 
 extern mempool_t *cifs_mid_poolp;
 
fs/cifs/file.c +11 -3
index 9793ae0bcaa2..d4890b6dc22d 100644
@@ -1112,6 +1112,12 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
 	return rc;
 }
 
+static __u32
+hash_lockowner(fl_owner_t owner)
+{
+	return cifs_lock_secret ^ hash32_ptr((const void *)owner);
+}
+
 struct lock_to_push {
 	struct list_head llist;
 	__u64 offset;
@@ -1178,7 +1184,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
 		else
 			type = CIFS_WRLCK;
 		lck = list_entry(el, struct lock_to_push, llist);
-		lck->pid = flock->fl_pid;
+		lck->pid = hash_lockowner(flock->fl_owner);
 		lck->netfid = cfile->fid.netfid;
 		lck->length = length;
 		lck->type = type;
@@ -1305,7 +1311,8 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 			posix_lock_type = CIFS_RDLCK;
 		else
 			posix_lock_type = CIFS_WRLCK;
-		rc = CIFSSMBPosixLock(xid, tcon, netfid, current->tgid,
+		rc = CIFSSMBPosixLock(xid, tcon, netfid,
+				      hash_lockowner(flock->fl_owner),
 				      flock->fl_start, length, flock,
 				      posix_lock_type, wait_flag);
 		return rc;
@@ -1505,7 +1512,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
 			posix_lock_type = CIFS_UNLCK;
 
 		rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid,
-				      current->tgid, flock->fl_start, length,
+				      hash_lockowner(flock->fl_owner),
+				      flock->fl_start, length,
 				      NULL, posix_lock_type, wait_flag);
 		goto out;
 	}
Signature · 1 line
2.5.5

A message that is not in the archive (sent off-list or not yet received): 1464085664-4391-1-git-send-email-jeff.layton-7I+n7zu2hftEKMMhf/[email protected]

#2 lore raw

2016-05-24 13:27 GMT+03:00 Jeff Layton <[email protected]>:

Quoted 96 lines

Right now, we send the tgid cross the wire. What we really want to send though is a hashed fl_owner_t since samba treats this field as a generic lockowner.

It turns out that because we enforce and release locks locally before they are ever sent to the server, this patch makes no difference in behavior. Still, setting OFD locks on the server using the process pid seems wrong, so I think this patch still makes sense.

---
 fs/cifs/cifsfs.c   |  3 +++
 fs/cifs/cifsglob.h |  1 +
 fs/cifs/file.c     | 14 +++++++++++---
 3 files changed, 15 insertions(+), 3 deletions(-)
fs/cifs/cifsfs.c +3 -0
index 08fa36e5b2bc..1ef5b8aee878 100644
@@ -87,6 +87,7 @@ extern mempool_t *cifs_req_poolp;
 extern mempool_t *cifs_mid_poolp;
 
 struct workqueue_struct        *cifsiod_wq;
+__u32 cifs_lock_secret;
 
 /*
  * Bumps refcount for cifs super block.
@@ -1271,6 +1272,8 @@ init_cifs(void)
        spin_lock_init(&cifs_file_list_lock);
        spin_lock_init(&GlobalMid_Lock);
 
+       get_random_bytes(&cifs_lock_secret, sizeof(cifs_lock_secret));
+
        if (cifs_max_pending < 2) {
                cifs_max_pending = 2;
                cifs_dbg(FYI, "cifs_max_pending set to min of 2\n");
fs/cifs/cifsglob.h +1 -0
index bba106cdc43c..8f1d8c1e72be 100644
@@ -1619,6 +1619,7 @@ void cifs_oplock_break(struct work_struct *work);
 
 extern const struct slow_work_ops cifs_oplock_break_ops;
 extern struct workqueue_struct *cifsiod_wq;
+extern __u32 cifs_lock_secret;
 
 extern mempool_t *cifs_mid_poolp;
 
fs/cifs/file.c +11 -4
index 9793ae0bcaa2..d4890b6dc22d 100644
@@ -1112,6 +1112,12 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
        return rc;
 }
 
+static __u32
+hash_lockowner(fl_owner_t owner)
+{
+       return cifs_lock_secret ^ hash32_ptr((const void *)owner);
+}
+
 struct lock_to_push {
        struct list_head llist;
        __u64 offset;
@@ -1178,7 +1184,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
                else
                        type = CIFS_WRLCK;
                lck = list_entry(el, struct lock_to_push, llist);
-               lck->pid = flock->fl_pid;
+               lck->pid = hash_lockowner(flock->fl_owner);
                lck->netfid = cfile->fid.netfid;
                lck->length = length;
                lck->type = type;
@@ -1305,7 +1311,8 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
                        posix_lock_type = CIFS_RDLCK;
                else
                        posix_lock_type = CIFS_WRLCK;
-               rc = CIFSSMBPosixLock(xid, tcon, netfid, current->tgid,
+               rc = CIFSSMBPosixLock(xid, tcon, netfid,
+                                     hash_lockowner(flock->fl_owner),
                                      flock->fl_start, length, flock,
                                      posix_lock_type, wait_flag);
                return rc;
@@ -1505,7 +1512,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
                        posix_lock_type = CIFS_UNLCK;
 
                rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid,
-                                     current->tgid, flock->fl_start, length,
+                                     hash_lockowner(flock->fl_owner),
+                                     flock->fl_start, length,
                                      NULL, posix_lock_type, wait_flag);
                goto out;
        }
--
Quoted 3 lines

2.5.5

Looks correct.

Signature · 2 lines
Best regards,
Pavel Shilovsky
Acked-by
#3 lore raw
In reply to a message not in the archive
Quoted 6 lines · Jeff Layton

Right now, we send the tgid cross the wire. What we really want to send
though is a hashed fl_owner_t since samba treats this field as a generic
lockowner.

Quoted 6 lines

It turns out that because we enforce and release locks locally before they are ever sent to the server, this patch makes no difference in behavior. Still, setting OFD locks on the server using the process pid seems wrong, so I think this patch still makes sense.

Quoted 97 lines

---
 fs/cifs/cifsfs.c   |  3 +++
 fs/cifs/cifsglob.h |  1 +
 fs/cifs/file.c     | 14 +++++++++++---

 3 files changed, 15 insertions(+), 3 deletions(-)
fs/cifs/cifsfs.c +0 -0
index 08fa36e5b2bc..1ef5b8aee878 100644
@@ -87,6 +87,7 @@ extern mempool_t *cifs_req_poolp;
  extern mempool_t *cifs_mid_poolp;


 struct workqueue_struct *cifsiod_wq;
+__u32 cifs_lock_secret;

 /*
  * Bumps refcount for cifs super block.

fs/cifs/cifsfs.c +0 -0
@@ -1271,6 +1272,8 @@ init_cifs(void)
  	spin_lock_init(&cifs_file_list_lock);
  	spin_lock_init(&GlobalMid_Lock);

fs/cifs/cifsfs.c +1 -0
+	get_random_bytes(&cifs_lock_secret,

sizeof(cifs_lock_secret));
+
  if (cifs_max_pending < 2) {
  cifs_max_pending = 2;
  cifs_dbg(FYI, "cifs_max_pending set to min of 2\n");

fs/cifs/cifsglob.h +0 -0
index bba106cdc43c..8f1d8c1e72be 100644
@@ -1619,6 +1619,7 @@ void cifs_oplock_break(struct work_struct
 *work);


 extern const struct slow_work_ops cifs_oplock_break_ops; extern struct workqueue_struct *cifsiod_wq; +extern __u32 cifs_lock_secret;

 extern mempool_t *cifs_mid_poolp;

fs/cifs/file.c +0 -0
index 9793ae0bcaa2..d4890b6dc22d 100644
@@ -1112,6 +1112,12 @@ cifs_push_mandatory_locks(struct cifsFileInfo
 *cfile)
  	return rc;
  }

fs/cifs/file.c +6 -0
+static __u32
+hash_lockowner(fl_owner_t owner)
+{
+	return cifs_lock_secret ^ hash32_ptr((const void *)owner);
+}
+

 struct lock_to_push {
  struct list_head llist;
  __u64 offset;

fs/cifs/file.c +0 -0
@@ -1178,7 +1184,7 @@ cifs_push_posix_locks(struct cifsFileInfo
 *cfile)

  else
  type = CIFS_WRLCK;
  lck = list_entry(el, struct lock_to_push, llist);

fs/cifs/file.c +1 -1
-		lck->pid = flock->fl_pid;
+		lck->pid = hash_lockowner(flock->fl_owner);

  lck->netfid = cfile->fid.netfid;
  lck->length = length;
  lck->type = type;

fs/cifs/file.c +0 -0
@@ -1305,7 +1311,8 @@ cifs_getlk(struct file *file, struct file_lock
 *flock, __u32 type,
  			posix_lock_type = CIFS_RDLCK;

  else
  posix_lock_type = CIFS_WRLCK;

fs/cifs/file.c +0 -1
-		rc = CIFSSMBPosixLock(xid, tcon, netfid, current-
Quoted 1 line

tgid,

fs/cifs/file.c +2 -0
+		rc = CIFSSMBPosixLock(xid, tcon, netfid,
+				      hash_lockowner(flock-
Quoted 1 line

fl_owner),

        flock->fl_start, length, flock,
        posix_lock_type, wait_flag); return rc;

fs/cifs/file.c +0 -0
@@ -1505,7 +1512,8 @@ cifs_setlk(struct file *file, struct file_lock
 *flock, __u32 type,
  			posix_lock_type = CIFS_UNLCK;


  rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid,

fs/cifs/file.c +0 -1
-				      current->tgid, flock-
Quoted 1 line

fl_start, length,

fs/cifs/file.c +1 -0
+				      hash_lockowner(flock-
Quoted 1 line

fl_owner),

fs/cifs/file.c +1 -0
+				      flock->fl_start, length,

        NULL, posix_lock_type, wait_flag);
  goto out;
  }