diff mbox

not overwriting file_lock structure after GET_LK

Message ID 201004050959.14953.piastry@etersoft.ru
State New
Headers show

Commit Message

piastry@etersoft.ru April 5, 2010, 5:59 a.m. UTC
From: Pavel Shilovsky <piastryyy@gmail.com>

If we have preventing lock, cifs should overwrite file_lock structure
with info about preventing lock. If we haven't preventing lock, cifs
should leave it unchanged except for the lock type (change it to F_UNLCK).

Signed-off-by: Pavel Shilovsky <piastryyy@gmail.com>
Reviewed-by: Jeff Layton <jlayton@samba.org>
---
 fs/cifs/cifssmb.c |   15 ++++++++++++++-
 fs/cifs/file.c    |   28 ++++++++++++++++++++++++++--
 2 files changed, 40 insertions(+), 3 deletions(-)

Comments

Jeff Layton April 5, 2010, 12:12 p.m. UTC | #1
On Mon, 5 Apr 2010 09:59:14 +0400
piastry@etersoft.ru wrote:

> From: Pavel Shilovsky <piastryyy@gmail.com>
> 
> If we have preventing lock, cifs should overwrite file_lock structure
> with info about preventing lock. If we haven't preventing lock, cifs
> should leave it unchanged except for the lock type (change it to F_UNLCK).
> 
> Signed-off-by: Pavel Shilovsky <piastryyy@gmail.com>
> Reviewed-by: Jeff Layton <jlayton@samba.org>
> ---
>  fs/cifs/cifssmb.c |   15 ++++++++++++++-
>  fs/cifs/file.c    |   28 ++++++++++++++++++++++++++--
>  2 files changed, 40 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
> index 7cc7f83..b3bbb2b 100644
> --- a/fs/cifs/cifssmb.c
> +++ b/fs/cifs/cifssmb.c
> @@ -1793,8 +1793,21 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
>  		}
>  		parm_data = (struct cifs_posix_lock *)
>  			((char *)&pSMBr->hdr.Protocol + data_offset);
> -		if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK))
> +		if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK))
>  			pLockData->fl_type = F_UNLCK;
> +		else {
> +			if (parm_data->lock_type ==
> +					__constant_cpu_to_le16(CIFS_RDLCK))
> +				pLockData->fl_type = F_RDLCK;
> +			else if (parm_data->lock_type ==
> +					__constant_cpu_to_le16(CIFS_WRLCK))
> +				pLockData->fl_type = F_WRLCK;
> +
> +			pLockData->fl_start = parm_data->start;
> +			pLockData->fl_end = parm_data->start +
> +						parm_data->length - 1;
> +			pLockData->fl_pid = parm_data->pid;
> +		}
>  	}
>  
>  plk_err_exit:
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index ca2ba7a..d9e8650 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -838,8 +838,32 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
>  
>  		} else {
>  			/* if rc == ERR_SHARING_VIOLATION ? */
> -			rc = 0;	/* do not change lock type to unlock
> -				   since range in use */
> +			rc = 0;
> +
> +			if (lockType & LOCKING_ANDX_SHARED_LOCK) {
> +				pfLock->fl_type = F_WRLCK;
> +			} else {
> +				rc = CIFSSMBLock(xid, tcon, netfid, length,
> +					pfLock->fl_start, 0, 1,
> +					lockType | LOCKING_ANDX_SHARED_LOCK,
> +					0 /* wait flag */);
> +				if (rc == 0) {
> +					rc = CIFSSMBLock(xid, tcon, netfid,
> +						length, pfLock->fl_start, 1, 0,
> +						lockType |
> +						LOCKING_ANDX_SHARED_LOCK,
> +						0 /* wait flag */);
> +					pfLock->fl_type = F_RDLCK;
> +					if (rc != 0)
> +						cERROR(1, ("Error unlocking "
> +						"previously locked range %d "
> +						"during test of lock", rc));
> +					rc = 0;
> +				} else {
> +					pfLock->fl_type = F_WRLCK;
> +					rc = 0;
> +				}
> +			}
>  		}
>  
>  		FreeXid(xid);

Looks good -- thanks for sticking with this.

Reviewed-by: Jeff Layton <jlayton@samba.org>
Steve French April 6, 2010, 5:24 p.m. UTC | #2
merged - thx for good work on this

On Mon, Apr 5, 2010 at 12:59 AM,  <piastry@etersoft.ru> wrote:
> From: Pavel Shilovsky <piastryyy@gmail.com>
>
> If we have preventing lock, cifs should overwrite file_lock structure
> with info about preventing lock. If we haven't preventing lock, cifs
> should leave it unchanged except for the lock type (change it to F_UNLCK).
>
> Signed-off-by: Pavel Shilovsky <piastryyy@gmail.com>
> Reviewed-by: Jeff Layton <jlayton@samba.org>
> ---
>  fs/cifs/cifssmb.c |   15 ++++++++++++++-
>  fs/cifs/file.c    |   28 ++++++++++++++++++++++++++--
>  2 files changed, 40 insertions(+), 3 deletions(-)
>
> diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
> index 7cc7f83..b3bbb2b 100644
> --- a/fs/cifs/cifssmb.c
> +++ b/fs/cifs/cifssmb.c
> @@ -1793,8 +1793,21 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
>                }
>                parm_data = (struct cifs_posix_lock *)
>                        ((char *)&pSMBr->hdr.Protocol + data_offset);
> -               if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK))
> +               if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK))
>                        pLockData->fl_type = F_UNLCK;
> +               else {
> +                       if (parm_data->lock_type ==
> +                                       __constant_cpu_to_le16(CIFS_RDLCK))
> +                               pLockData->fl_type = F_RDLCK;
> +                       else if (parm_data->lock_type ==
> +                                       __constant_cpu_to_le16(CIFS_WRLCK))
> +                               pLockData->fl_type = F_WRLCK;
> +
> +                       pLockData->fl_start = parm_data->start;
> +                       pLockData->fl_end = parm_data->start +
> +                                               parm_data->length - 1;
> +                       pLockData->fl_pid = parm_data->pid;
> +               }
>        }
>
>  plk_err_exit:
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index ca2ba7a..d9e8650 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -838,8 +838,32 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
>
>                } else {
>                        /* if rc == ERR_SHARING_VIOLATION ? */
> -                       rc = 0; /* do not change lock type to unlock
> -                                  since range in use */
> +                       rc = 0;
> +
> +                       if (lockType & LOCKING_ANDX_SHARED_LOCK) {
> +                               pfLock->fl_type = F_WRLCK;
> +                       } else {
> +                               rc = CIFSSMBLock(xid, tcon, netfid, length,
> +                                       pfLock->fl_start, 0, 1,
> +                                       lockType | LOCKING_ANDX_SHARED_LOCK,
> +                                       0 /* wait flag */);
> +                               if (rc == 0) {
> +                                       rc = CIFSSMBLock(xid, tcon, netfid,
> +                                               length, pfLock->fl_start, 1, 0,
> +                                               lockType |
> +                                               LOCKING_ANDX_SHARED_LOCK,
> +                                               0 /* wait flag */);
> +                                       pfLock->fl_type = F_RDLCK;
> +                                       if (rc != 0)
> +                                               cERROR(1, ("Error unlocking "
> +                                               "previously locked range %d "
> +                                               "during test of lock", rc));
> +                                       rc = 0;
> +                               } else {
> +                                       pfLock->fl_type = F_WRLCK;
> +                                       rc = 0;
> +                               }
> +                       }
>                }
>
>                FreeXid(xid);
> --
> 1.6.6.1
>
diff mbox

Patch

diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 7cc7f83..b3bbb2b 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -1793,8 +1793,21 @@  CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
 		}
 		parm_data = (struct cifs_posix_lock *)
 			((char *)&pSMBr->hdr.Protocol + data_offset);
-		if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK))
+		if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK))
 			pLockData->fl_type = F_UNLCK;
+		else {
+			if (parm_data->lock_type ==
+					__constant_cpu_to_le16(CIFS_RDLCK))
+				pLockData->fl_type = F_RDLCK;
+			else if (parm_data->lock_type ==
+					__constant_cpu_to_le16(CIFS_WRLCK))
+				pLockData->fl_type = F_WRLCK;
+
+			pLockData->fl_start = parm_data->start;
+			pLockData->fl_end = parm_data->start +
+						parm_data->length - 1;
+			pLockData->fl_pid = parm_data->pid;
+		}
 	}
 
 plk_err_exit:
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index ca2ba7a..d9e8650 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -838,8 +838,32 @@  int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
 
 		} else {
 			/* if rc == ERR_SHARING_VIOLATION ? */
-			rc = 0;	/* do not change lock type to unlock
-				   since range in use */
+			rc = 0;
+
+			if (lockType & LOCKING_ANDX_SHARED_LOCK) {
+				pfLock->fl_type = F_WRLCK;
+			} else {
+				rc = CIFSSMBLock(xid, tcon, netfid, length,
+					pfLock->fl_start, 0, 1,
+					lockType | LOCKING_ANDX_SHARED_LOCK,
+					0 /* wait flag */);
+				if (rc == 0) {
+					rc = CIFSSMBLock(xid, tcon, netfid,
+						length, pfLock->fl_start, 1, 0,
+						lockType |
+						LOCKING_ANDX_SHARED_LOCK,
+						0 /* wait flag */);
+					pfLock->fl_type = F_RDLCK;
+					if (rc != 0)
+						cERROR(1, ("Error unlocking "
+						"previously locked range %d "
+						"during test of lock", rc));
+					rc = 0;
+				} else {
+					pfLock->fl_type = F_WRLCK;
+					rc = 0;
+				}
+			}
 		}
 
 		FreeXid(xid);