From patchwork Fri Feb 9 13:15:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meetakshi Setiya X-Patchwork-Id: 13551202 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8656529CF8; Fri, 9 Feb 2024 13:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707484574; cv=none; b=jI60KItYk3zM/rGLsqc25SrhbUkcXiPfUX443gRmlhvnGnMnbtb+V4lzNz/CX0eaIFT6biwoTzkmXhFBRHr/y/uLDilqIU0Z0RM0RxraU7FUZP3lkvDpysdWm9fSaOkwdr+9jicHD3JSjBFOeKE2bu4cnQDw0um/GlQywemLVNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707484574; c=relaxed/simple; bh=kEOW6Ro1dUaEB7NjwI9r+6JbRCQpGLp6wJfykrsNJak=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=cRmJhCDTx8GSQeaLzlk4F3awfluh+YfX6lLOquYRlz2L66apI8lq5xu89IepmyPkypTxsmhQzD/X4EWOXZSXN3qB85QpZ34PFduvRA1HcauTbzVFvjOsGLXP+FSAqY70/HrN8sJiOIPs4uR9fCiK2w0njHN3eb+te7OlE5mtd18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TDE+rA/C; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TDE+rA/C" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1d51ba18e1bso8963905ad.0; Fri, 09 Feb 2024 05:16:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707484572; x=1708089372; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XKfVxq5s1e2ISbkZ5F17DY5TtUz/n+URrbxrOrInYCY=; b=TDE+rA/CIUHMRe6IPN9BHAtZy08IWcxObQTNEOObo5pwAsHLXMHQW3/oEwzyh37N/P SpkAJp83BTARY8F2QTru+z8B8v8YUNkGxD14FOXEvYUjF1SOc/bgEqAB5Hh/bOCRd8zd ZhpYwDpprFWw6WFCFxGrIZ/sLXfFIYxSPE+H3vdE9jmAe/EjwTix/KjBLOpaEgKXGCIM YkP05Q8xgC8Ej141E0KXND60zFgT0o5ft/On+KDpU0VMvvsAe48Z0lqhZsvDI4TvOeA1 BSIKQDlakL0ajfcUDiNBfYDBIdxAAn4GAg6eCJ+9sYdqIYhKoXEhi5RClR/SPZgoNgEN yINA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707484572; x=1708089372; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XKfVxq5s1e2ISbkZ5F17DY5TtUz/n+URrbxrOrInYCY=; b=YSLXRrRNTPhqrdukwi3a7L6K1+utSXSLBVjUdLT4m/IjaMaPud4X4w8M6QAH48buPy iENWGEF3+QvijheMNLgwCcmAL1qLqPv3zAKEO6cFaRvOwcZq4CxofA6YJu8gzwkNqIbZ FpyKGZxJDukQ4kCq+iuS/trydgxGZyO0AbWJ+xFSF84gf0oIQUyZfvXVNhe9oOVLQEPG x4Z26pAd8CUF89MMaYNCA+X27lJ9AqyUSQukYXLIcv5BbfxL1XMFAI9d30hRv4+VRu5A A4gJ8v7g+X8soHBTQUPaYtdTRQgC5u0YkKg7yeONIr6hrkw/SQEXe8J0sLcXs//DXg4y I1Vg== X-Gm-Message-State: AOJu0Yz1ryDk7xee8KUde2CnHDK0DL93XrHlKjoqnCLbbiHnYSokf+oy qSPDS3RdPujM7haQR/G+eTmXHeBzcbAWz3xT+x1I+1lmM4FkskZEcnGvioJg9y0= X-Google-Smtp-Source: AGHT+IHaaqh7V9zPP+RRLUmIG7cWfmh8KmAyvuseL/ii0IlCWo68UeHBZ5gpBCMtyoA7EmlNz9m+FQ== X-Received: by 2002:a17:902:d512:b0:1d4:cd4d:923b with SMTP id b18-20020a170902d51200b001d4cd4d923bmr1531154plg.54.1707484571675; Fri, 09 Feb 2024 05:16:11 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWOarCWTYeKNHl4lSbPfL9Z3nEMu3SkPbMqzpP/P8doPEQX8T37Rn0JxmVA3hmpDacprRhnD6SI3mffUgOagQ+U48P5z6dX3i2kXD+T9/rXX5Dr75b0uV9GY7fvFrL6VI+uNyWI6qoYyGhuHfu2t5KjClLrI42gscVZhGsRlScXB7t63rsOoNcxaQTwHKraMSbbSBGVa+wcGIPzE1ANlPb/INdIfkJ+lfnRO4bzP8VvRxclteZzaNySxUsRSgMsaX1Udz6kfsV+b+/S7JpvWc+3eXDIjNRd3A3hQfVcrt49EG4R/Uq0R4f7q81qgOKZaXithFMCFqHLZg3C8pbi3m/rEMgApjuKaqxGXl/mTw== Received: from met-Virtual-Machine.. ([131.107.1.159]) by smtp.gmail.com with ESMTPSA id sk12-20020a17090b2dcc00b00296540086a5sm1713246pjb.23.2024.02.09.05.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 05:16:11 -0800 (PST) From: meetakshisetiyaoss@gmail.com To: sfrench@samba.org, pc@manguebit.com, ronniesahlberg@gmail.com, sprasad@microsoft.com, nspmangalore@gmail.com, tom@talpey.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, samba-technical@lists.samba.org, bharathsm.hsk@gmail.com Cc: Meetakshi Setiya Subject: [PATCH 1/3] smb: client: do not defer close open handles to deleted files Date: Fri, 9 Feb 2024 08:15:50 -0500 Message-Id: <20240209131552.471765-1-meetakshisetiyaoss@gmail.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Meetakshi Setiya When a file/dentry has been deleted before closing all its open handles, currently, closing them can add them to the deferred close list. This can lead to problems in creating file with the same name when the file is re-created before the deferred close completes. This issue was seen while reusing a client's already existing lease on a file for compound operations and xfstest 591 failed because of the deferred close handle that remained valid even after the file was deleted and was being reused to create a file with the same name. The server in this case returns an error on open with STATUS_DELETE_PENDING. Recreating the file would fail till the deferred handles are closed (duration specified in closetimeo). This patch fixes the issue by flagging all open handles for the deleted file (file path to be precise) with FILE_DELETED at the end of the unlink operation. A new field cflags has been introduced in the cifsFileInfo structure to set the FILE_DELETED flag without interfering with the f_flags field. This cflags field could be useful in the future for setting more flags specific to cfile. When doing close in cifs_close for each of these handles, check the FILE_DELETED flag and do not defer close these handles if the corresponding filepath has been deleted. Signed-off-by: Meetakshi Setiya --- fs/smb/client/cifsglob.h | 3 +++ fs/smb/client/cifsproto.h | 4 ++++ fs/smb/client/file.c | 3 ++- fs/smb/client/inode.c | 2 ++ fs/smb/client/misc.c | 22 ++++++++++++++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 16befff4cbb4..f6b4acdcdeb3 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -1398,6 +1398,8 @@ struct cifs_fid_locks { struct list_head locks; /* locks held by fid above */ }; +#define FILE_DELETED 00000001 + struct cifsFileInfo { /* following two lists are protected by tcon->open_file_lock */ struct list_head tlist; /* pointer to next fid owned by tcon */ @@ -1413,6 +1415,7 @@ struct cifsFileInfo { struct dentry *dentry; struct tcon_link *tlink; unsigned int f_flags; + unsigned int cflags; /* flags for this file */ bool invalidHandle:1; /* file closed via session abend */ bool swapfile:1; bool oplock_break_cancelled:1; diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index a841bf4967fa..f995b766b177 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -296,6 +296,10 @@ extern void cifs_close_all_deferred_files(struct cifs_tcon *cifs_tcon); extern void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon, const char *path); + +extern void cifs_mark_open_handles_for_deleted_file(struct cifs_tcon + *cifs_tcon, const char *path); + extern struct TCP_Server_Info * cifs_get_tcp_session(struct smb3_fs_context *ctx, struct TCP_Server_Info *primary_server); diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index b75282c204da..91cf4d2df4de 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -483,6 +483,7 @@ struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, cfile->uid = current_fsuid(); cfile->dentry = dget(dentry); cfile->f_flags = file->f_flags; + cfile->cflags = 0; cfile->invalidHandle = false; cfile->deferred_close_scheduled = false; cfile->tlink = cifs_get_tlink(tlink); @@ -1085,7 +1086,7 @@ int cifs_close(struct inode *inode, struct file *file) if ((cifs_sb->ctx->closetimeo && cinode->oplock == CIFS_CACHE_RHW_FLG) && cinode->lease_granted && !test_bit(CIFS_INO_CLOSE_ON_LOCK, &cinode->flags) && - dclose) { + dclose && !(cfile->cflags & FILE_DELETED)) { if (test_and_clear_bit(CIFS_INO_MODIFIED_ATTR, &cinode->flags)) { inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index d02f8ba29cb5..8121b5b1aa22 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1900,6 +1900,8 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) cifs_inode = CIFS_I(dir); CIFS_I(dir)->time = 0; /* force revalidate of dir as well */ unlink_out: + if (rc == 0) + cifs_mark_open_handles_for_deleted_file(tcon, full_path); free_dentry_path(page); kfree(attrs); free_xid(xid); diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index 0748d7b757b9..8e46dee1a36c 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -853,6 +853,28 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path) free_dentry_path(page); } +/* + * If a dentry has been deleted, all corresponding open handles should know that + * so that we do not defer close them. + */ +void cifs_mark_open_handles_for_deleted_file(struct cifs_tcon *tcon, + const char *path) +{ + struct cifsFileInfo *cfile; + void *page; + const char *full_path; + + page = alloc_dentry_path(); + spin_lock(&tcon->open_file_lock); + list_for_each_entry(cfile, &tcon->openFileList, tlist) { + full_path = build_path_from_dentry(cfile->dentry, page); + if (strcmp(full_path, path) == 0) + cfile->cflags |= FILE_DELETED; + } + spin_unlock(&tcon->open_file_lock); + free_dentry_path(page); +} + /* parses DFS referral V3 structure * caller is responsible for freeing target_nodes * returns: From patchwork Fri Feb 9 13:15:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meetakshi Setiya X-Patchwork-Id: 13551203 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 855173838B; Fri, 9 Feb 2024 13:16:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707484598; cv=none; b=Vyck/SzA6NzYLz5ooZuNsVllsf3mvxOE43j5qHuYABOLDYiUKY2V/K8HHywjj2LGohxye5D1fNnxfYSSJ0lMae1Ou9Le3hYUreu+8uDdLahyKWefQ2lRUqVqoMJ1ycarsQC4DgEhctSqy8hyJv9VWqbZ0ed3oou8KZHwEI5mOps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707484598; c=relaxed/simple; bh=mlbyP/hGrhAG5lydCe0HnnMzTUIJQkv1pUt80jvevLg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UILGNpApNuz0iPrIpnGJ6iBIP0mFelSA4fGqkHRTm7MLN4c5d4daHzAtgbeKtFP8tzR6Pgxblcv2pCcoSTS2GmGEamIKcw/opioXuOUBJvLFsQrkiLEjBP5ra9FHcv9vz9BeRWRRpMkVR6y3jP9raz05l4j7ICUV1KfS14w2H2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TISZ/GRi; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TISZ/GRi" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-5d8df34835aso736966a12.0; Fri, 09 Feb 2024 05:16:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707484596; x=1708089396; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7ERbNxLdk3eu5PTJj3FXF/TXouUoeq2Q9p3QCLY8PJA=; b=TISZ/GRiAhnk7mVdPaD1w/oaZEP64WoKOhqg8FVRJIb1vZYpbn3MZbK/H7FGMNnn52 CkDtvrTV8T6BHX56kCbRHcT0RXjfA6pI0ntHpV7rxovWuJlL0j27OPmt/fOuoxgDqTqv quyP5wcclnvdb4kQQa8E9nIrSf+d17gLnGg4U9bUwIL61hRRcxCcDf82f24OfDwvasBi bTV9wtiXowwMOYFZvrprf6BVlZFtLhB5NT4Q1o/X92wWVmcLTeUL9gNzy3XWlV5ApRwr GohvLFdyZ9nHCn6zCCGldxitzWvsJYd4zu/2/liSVmKxubvZ2BpdVC113IwfERB/o49Q 3a0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707484596; x=1708089396; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7ERbNxLdk3eu5PTJj3FXF/TXouUoeq2Q9p3QCLY8PJA=; b=McIIrw1fMQmGHn7q58vrttgIYIRCpGtg2/hWy0zg+McggTs6mE+glhngpTYW19zdqu AFNpSGpwPy9FCbCzIVNvS6ltWJDH3lfhRrHzIu/Uzs9JEUD4NFgXUfAKNNeTHE7rCYzC Tp2QORTrSAX5NToUPNY0JGwr05h9gaZFxyFKj8H74sbRh5DJlK3IJKBTfPbzF8muHskg QYeQlF1XT2DGQGUhTMFeXODVrzdHl+R1bREuj5GBZ8Agk5Sx39/De6JamxRTdG7zS3nR Yxjv9u6YemLKbZBlMcwM9h32/mVtX03/rTDWEhYjqp0D76NXW7uTxO8NI1rbgMr0Behb /Sfg== X-Forwarded-Encrypted: i=1; AJvYcCV2/UTu27uG4h30SDZW40JRfik1E3Wizo0E/xLI45upm0Ykg+MKyYmYDgCCIMsqxESQKQm8moiFJp3685pUsfYXZtxfRTJotHu+5yzN/3uc1tgR5uV50Wzz6OtR5yK7j+8Vkom7YR3tWA== X-Gm-Message-State: AOJu0YwqGhK65vdio3RD93Wa0XcNeTa0hqWqyZjMu5eULR/Nksq8DELL kxpl+UDwKuqcK9/oHMheGzrJypx9eeM6YjBEHcDSk4FuoPph2CrSKPaOOs9sITU= X-Google-Smtp-Source: AGHT+IE8WtpaDlyspsHyczZ4PLUpUSajf6lqBHC8xJ1yXD8k8myRj54gcfatidtponY4sTE6jj9Aew== X-Received: by 2002:a17:90a:b398:b0:296:2865:cc17 with SMTP id e24-20020a17090ab39800b002962865cc17mr1341223pjr.20.1707484595676; Fri, 09 Feb 2024 05:16:35 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVUBIZoE+grvZG15GctK26AFrv37nxN1XJ6ZUX1OoKjmwYsl8FKR8wL54vmuaqk67eszK3Id+OUsE3XICeJoJnr93dN+tSg2rjvplGn7xxwURzShARLeBAzpEFpr+QNFx5Y+GcsOom5gIDl5SABJ2Hv2nDffeBiXbk3DxAO3loJHhMSDUfYfpAU+a/qokRKUZ5WEYj63fdcAOXIwJ+2guz8k5w1kAkRxOpU+iOEp7j0uNARccD+F0nirR0HiQmcZA8q0xkQj418O9GHcOuzhrnQwIGgUMb+Ch6gtA8aRDvDrJ9HIOWmt/D/9eIsJuzvr8/lmb0Lt+h0EF35A2LHiF2AvikyxE5HTxTvQpHHgA== Received: from met-Virtual-Machine.. ([131.107.1.159]) by smtp.gmail.com with ESMTPSA id sk12-20020a17090b2dcc00b00296540086a5sm1713246pjb.23.2024.02.09.05.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 05:16:35 -0800 (PST) From: meetakshisetiyaoss@gmail.com To: sfrench@samba.org, pc@manguebit.com, ronniesahlberg@gmail.com, sprasad@microsoft.com, nspmangalore@gmail.com, tom@talpey.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, samba-technical@lists.samba.org, bharathsm.hsk@gmail.com Cc: Meetakshi Setiya Subject: [PATCH 2/3] smb: client: reuse file lease key in compound operations Date: Fri, 9 Feb 2024 08:15:51 -0500 Message-Id: <20240209131552.471765-2-meetakshisetiyaoss@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240209131552.471765-1-meetakshisetiyaoss@gmail.com> References: <20240209131552.471765-1-meetakshisetiyaoss@gmail.com> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Meetakshi Setiya Currently, when a rename, unlink or set path size compound operation is requested on a file that has a lot of dirty pages to be written to the server, we do not send the lease key for these requests. As a result, the server can assume that this request is from a new client, and send a lease break notification to the same client, on the same connection. As a response to the lease break, the client can consume several credits to write the dirty pages to the server. Depending on the server's credit grant implementation, the server can stop granting more credits to this connection, and this can cause a deadlock (which can only be resolved when the lease timer on the server expires). One of the problems here is that the client is sending no lease key, even if it has a lease for the file. This patch fixes the problem by reusing the existing lease key on the file for rename, unlink and set path size compound operations so that the client does not break its own lease. A very trivial example could be a set of commands by a client that maintains open handle (for write) to a file and then tries to copy the contents of that file to another one, eg., tail -f /dev/null > myfile & mv myfile myfile2 Presently, the network capture on the client shows that the move (or rename) would trigger a lease break on the same client, for the same file. With the lease key reused, the lease break request-response overhead is eliminated, thereby reducing the roundtrips performed for this set of operations. The patch fixes the bug described above and also provides perf benefit. Signed-off-by: Meetakshi Setiya --- fs/smb/client/cifsglob.h | 5 ++-- fs/smb/client/cifsproto.h | 6 +++-- fs/smb/client/cifssmb.c | 4 ++-- fs/smb/client/inode.c | 10 ++++---- fs/smb/client/smb2inode.c | 48 ++++++++++++++++++++++++--------------- fs/smb/client/smb2proto.h | 6 +++-- 6 files changed, 48 insertions(+), 31 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index f6b4acdcdeb3..baeed01d356b 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -371,7 +371,8 @@ struct smb_version_operations { struct cifs_open_info_data *data); /* set size by path */ int (*set_path_size)(const unsigned int, struct cifs_tcon *, - const char *, __u64, struct cifs_sb_info *, bool); + const char *, __u64, struct cifs_sb_info *, bool, + struct dentry *); /* set size by file handle */ int (*set_file_size)(const unsigned int, struct cifs_tcon *, struct cifsFileInfo *, __u64, bool); @@ -401,7 +402,7 @@ struct smb_version_operations { struct cifs_sb_info *); /* unlink file */ int (*unlink)(const unsigned int, struct cifs_tcon *, const char *, - struct cifs_sb_info *); + struct cifs_sb_info *, struct dentry *); /* open, rename and delete file */ int (*rename_pending_delete)(const char *, struct dentry *, const unsigned int); diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index f995b766b177..e108964950b5 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -406,7 +406,8 @@ extern int CIFSSMBSetFileDisposition(const unsigned int xid, __u32 pid_of_opener); extern int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, const char *file_name, __u64 size, - struct cifs_sb_info *cifs_sb, bool set_allocation); + struct cifs_sb_info *cifs_sb, bool set_allocation, + struct dentry *dentry); extern int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, struct cifsFileInfo *cfile, __u64 size, bool set_allocation); @@ -442,7 +443,8 @@ extern int CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, const struct nls_table *nls_codepage, int remap_special_chars); extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, - const char *name, struct cifs_sb_info *cifs_sb); + const char *name, struct cifs_sb_info *cifs_sb, + struct dentry *dentry); int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, struct dentry *source_dentry, const char *from_name, const char *to_name, diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 01e89070df5a..301189ee1335 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -738,7 +738,7 @@ CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name, - struct cifs_sb_info *cifs_sb) + struct cifs_sb_info *cifs_sb, struct dentry *dentry) { DELETE_FILE_REQ *pSMB = NULL; DELETE_FILE_RSP *pSMBr = NULL; @@ -4993,7 +4993,7 @@ CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, const char *file_name, __u64 size, struct cifs_sb_info *cifs_sb, - bool set_allocation) + bool set_allocation, struct dentry *dentry) { struct smb_com_transaction2_spi_req *pSMB = NULL; struct smb_com_transaction2_spi_rsp *pSMBr = NULL; diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 8121b5b1aa22..c3e86876a2a8 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1846,7 +1846,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) goto psx_del_no_retry; } - rc = server->ops->unlink(xid, tcon, full_path, cifs_sb); + rc = server->ops->unlink(xid, tcon, full_path, cifs_sb, dentry); psx_del_no_retry: if (!rc) { @@ -2799,7 +2799,7 @@ void cifs_setsize(struct inode *inode, loff_t offset) static int cifs_set_file_size(struct inode *inode, struct iattr *attrs, - unsigned int xid, const char *full_path) + unsigned int xid, const char *full_path, struct dentry *dentry) { int rc; struct cifsFileInfo *open_file; @@ -2850,7 +2850,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, */ if (server->ops->set_path_size) rc = server->ops->set_path_size(xid, tcon, full_path, - attrs->ia_size, cifs_sb, false); + attrs->ia_size, cifs_sb, false, dentry); else rc = -ENOSYS; cifs_dbg(FYI, "SetEOF by path (setattrs) rc = %d\n", rc); @@ -2940,7 +2940,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) rc = 0; if (attrs->ia_valid & ATTR_SIZE) { - rc = cifs_set_file_size(inode, attrs, xid, full_path); + rc = cifs_set_file_size(inode, attrs, xid, full_path, direntry); if (rc != 0) goto out; } @@ -3107,7 +3107,7 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) } if (attrs->ia_valid & ATTR_SIZE) { - rc = cifs_set_file_size(inode, attrs, xid, full_path); + rc = cifs_set_file_size(inode, attrs, xid, full_path, direntry); if (rc != 0) goto cifs_setattr_exit; } diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index 05818cd6d932..69f3442c5b96 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -98,7 +98,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, __u32 desired_access, __u32 create_disposition, __u32 create_options, umode_t mode, struct kvec *in_iov, int *cmds, int num_cmds, struct cifsFileInfo *cfile, - struct kvec *out_iov, int *out_buftype) + struct kvec *out_iov, int *out_buftype, struct dentry *dentry) { struct reparse_data_buffer *rbuf; @@ -115,6 +115,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, int resp_buftype[MAX_COMPOUND]; struct smb2_query_info_rsp *qi_rsp = NULL; struct cifs_open_info_data *idata; + struct inode *inode = NULL; int flags = 0; __u8 delete_pending[8] = {1, 0, 0, 0, 0, 0, 0, 0}; unsigned int size[2]; @@ -152,6 +153,15 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, goto finished; } + /* if there is an existing lease, reuse it */ + if (dentry) { + inode = d_inode(dentry); + if (CIFS_I(inode)->lease_granted && server->ops->get_lease_key) { + oplock = SMB2_OPLOCK_LEVEL_LEASE; + server->ops->get_lease_key(inode, &fid); + } + } + vars->oparms = (struct cifs_open_parms) { .tcon = tcon, .path = full_path, @@ -747,7 +757,7 @@ int smb2_query_path_info(const unsigned int xid, rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN, create_options, ACL_NO_MODE, in_iov, - cmds, 1, cfile, out_iov, out_buftype); + cmds, 1, cfile, out_iov, out_buftype, NULL); hdr = out_iov[0].iov_base; /* * If first iov is unset, then SMB session was dropped or we've got a @@ -779,7 +789,7 @@ int smb2_query_path_info(const unsigned int xid, rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN, create_options, ACL_NO_MODE, in_iov, - cmds, num_cmds, cfile, NULL, NULL); + cmds, num_cmds, cfile, NULL, NULL, NULL); break; case -EREMOTE: break; @@ -811,7 +821,7 @@ smb2_mkdir(const unsigned int xid, struct inode *parent_inode, umode_t mode, FILE_WRITE_ATTRIBUTES, FILE_CREATE, CREATE_NOT_FILE, mode, NULL, &(int){SMB2_OP_MKDIR}, 1, - NULL, NULL, NULL); + NULL, NULL, NULL, NULL); } void @@ -836,7 +846,7 @@ smb2_mkdir_setinfo(struct inode *inode, const char *name, FILE_WRITE_ATTRIBUTES, FILE_CREATE, CREATE_NOT_FILE, ACL_NO_MODE, &in_iov, &(int){SMB2_OP_SET_INFO}, 1, - cfile, NULL, NULL); + cfile, NULL, NULL, NULL); if (tmprc == 0) cifs_i->cifsAttrs = dosattrs; } @@ -850,25 +860,26 @@ smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, DELETE, FILE_OPEN, CREATE_NOT_FILE, ACL_NO_MODE, NULL, &(int){SMB2_OP_RMDIR}, 1, - NULL, NULL, NULL); + NULL, NULL, NULL, NULL); } int smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, - struct cifs_sb_info *cifs_sb) + struct cifs_sb_info *cifs_sb, struct dentry *dentry) { return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT, ACL_NO_MODE, NULL, &(int){SMB2_OP_DELETE}, 1, - NULL, NULL, NULL); + NULL, NULL, NULL, dentry); } static int smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon, const char *from_name, const char *to_name, struct cifs_sb_info *cifs_sb, __u32 create_options, __u32 access, - int command, struct cifsFileInfo *cfile) + int command, struct cifsFileInfo *cfile, + struct dentry *dentry) { struct kvec in_iov; __le16 *smb2_to_name = NULL; @@ -883,7 +894,7 @@ static int smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon, in_iov.iov_len = 2 * UniStrnlen((wchar_t *)smb2_to_name, PATH_MAX); rc = smb2_compound_op(xid, tcon, cifs_sb, from_name, access, FILE_OPEN, create_options, ACL_NO_MODE, - &in_iov, &command, 1, cfile, NULL, NULL); + &in_iov, &command, 1, cfile, NULL, NULL, dentry); smb2_rename_path: kfree(smb2_to_name); return rc; @@ -902,7 +913,7 @@ int smb2_rename_path(const unsigned int xid, cifs_get_writable_path(tcon, from_name, FIND_WR_WITH_DELETE, &cfile); return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, - co, DELETE, SMB2_OP_RENAME, cfile); + co, DELETE, SMB2_OP_RENAME, cfile, source_dentry); } int smb2_create_hardlink(const unsigned int xid, @@ -915,13 +926,14 @@ int smb2_create_hardlink(const unsigned int xid, return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, co, FILE_READ_ATTRIBUTES, - SMB2_OP_HARDLINK, NULL); + SMB2_OP_HARDLINK, NULL, NULL); } int smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, const char *full_path, __u64 size, - struct cifs_sb_info *cifs_sb, bool set_alloc) + struct cifs_sb_info *cifs_sb, bool set_alloc, + struct dentry *dentry) { struct cifsFileInfo *cfile; struct kvec in_iov; @@ -934,7 +946,7 @@ smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, FILE_WRITE_DATA, FILE_OPEN, 0, ACL_NO_MODE, &in_iov, &(int){SMB2_OP_SET_EOF}, 1, - cfile, NULL, NULL); + cfile, NULL, NULL, dentry); } int @@ -963,7 +975,7 @@ smb2_set_file_info(struct inode *inode, const char *full_path, FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, ACL_NO_MODE, &in_iov, &(int){SMB2_OP_SET_INFO}, 1, - cfile, NULL, NULL); + cfile, NULL, NULL, NULL); cifs_put_tlink(tlink); return rc; } @@ -998,7 +1010,7 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data, cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile); rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, da, cd, co, ACL_NO_MODE, in_iov, - cmds, 2, cfile, NULL, NULL); + cmds, 2, cfile, NULL, NULL, NULL); if (!rc) { rc = smb311_posix_get_inode_info(&new, full_path, data, sb, xid); @@ -1008,7 +1020,7 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data, cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile); rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, da, cd, co, ACL_NO_MODE, in_iov, - cmds, 2, cfile, NULL, NULL); + cmds, 2, cfile, NULL, NULL, NULL); if (!rc) { rc = cifs_get_inode_info(&new, full_path, data, sb, xid, NULL); @@ -1036,7 +1048,7 @@ int smb2_query_reparse_point(const unsigned int xid, FILE_READ_ATTRIBUTES, FILE_OPEN, OPEN_REPARSE_POINT, ACL_NO_MODE, &in_iov, &(int){SMB2_OP_GET_REPARSE}, 1, - cfile, NULL, NULL); + cfile, NULL, NULL, NULL); if (rc) goto out; diff --git a/fs/smb/client/smb2proto.h b/fs/smb/client/smb2proto.h index b3069911e9dd..221143788a1c 100644 --- a/fs/smb/client/smb2proto.h +++ b/fs/smb/client/smb2proto.h @@ -75,7 +75,8 @@ int smb2_query_path_info(const unsigned int xid, struct cifs_open_info_data *data); extern int smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, const char *full_path, __u64 size, - struct cifs_sb_info *cifs_sb, bool set_alloc); + struct cifs_sb_info *cifs_sb, bool set_alloc, + struct dentry *dentry); extern int smb2_set_file_info(struct inode *inode, const char *full_path, FILE_BASIC_INFO *buf, const unsigned int xid); extern int smb311_posix_mkdir(const unsigned int xid, struct inode *inode, @@ -91,7 +92,8 @@ extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path, extern int smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, struct cifs_sb_info *cifs_sb); extern int smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, - const char *name, struct cifs_sb_info *cifs_sb); + const char *name, struct cifs_sb_info *cifs_sb, + struct dentry *dentry); int smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon, struct dentry *source_dentry, From patchwork Fri Feb 9 13:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meetakshi Setiya X-Patchwork-Id: 13551204 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEB5037716; Fri, 9 Feb 2024 13:16:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707484605; cv=none; b=aA6iiyr1cKDRQV7S2dfGLjSoehCjQeVIFglN/MrJZXaejmNO9DFBkHL7FH1TpxLg0tSF8f9r37HR2eOvWNHlEUr1hdtVvWOiQa9B7I8M1Zkwz33GF47iVjkN+mBxwy3FtCFu88PEk3zm85u2/PXHTMsZVr0yUxTaFm4p5cUq9TQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707484605; c=relaxed/simple; bh=qhOoCQNzPzHiOCmjwCButX1WGPZUV4R16n68RDJmqt8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OUwOMMaDgyHF6RLW/TmEjElvPkYiMf/r68VBdHxSieRUgw4gJzLcwIdEQHm5fovftTRcXz5GOVMG5YV9EVR4yt6daGGMguOEP/8PEot0gwuHeC3zQkINRNc87+PZb3qRWl3k0tpmXobHRSCHZhWHAGRvpbMCKjntWznMUTqpA6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EXcj3iuY; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EXcj3iuY" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-5cdf76cde78so668885a12.1; Fri, 09 Feb 2024 05:16:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707484603; x=1708089403; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rDApktuVCr/Bgtqf/JWCLMMqtiZv/VT6n1DxWHxTHaM=; b=EXcj3iuYmobodLEoGWEJRxop6W1lZlhGPW69eWIGPFlBqLx3UD9HQlphKSgDCr7juo x5LdcgcIzYdxIHsGq7zrZUxn4/F6LVhUdx84MhsBz7iMbAfWmskX9JsuxyAD/AFxMxiJ dGo0bsCGKF0rQ3YpkTNKmv6xlbiH9222qnrbam13pK4oqlr0BYNmjqtMTituFhMYnWF4 QX8cxc1kxtQDDGo3t5GESdx6Whs7vH4HWamzYcdD2EEMvPs3F1NDQ+nhNZIXlMJSiA8Z KMMTMZsW1cJprm2Zm8P2keXKBbNWWHFookYsR5a8JkiUbJ8MM1YKkYqWxNwiIv5SdZLD sTUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707484603; x=1708089403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rDApktuVCr/Bgtqf/JWCLMMqtiZv/VT6n1DxWHxTHaM=; b=R2uZUYXX6WGT8VZfy2qzg0SmmgmvYUH64iYPGD5NQ4Rej730U2koEVhFz55dg/MYZG Q/5o4mshWi5bEfNdPM1O8BDa3bPmv0x4OC6evwaSR3alXakeX6NDHz1IUwemvKvyHsDS 9/MAfrkMV7pQz161RJSTBIG2bT9xY18t2krW7uA8WwYRpZU8q3H8M1APgOFP78J9ssto uUMauxlNoXu1yNSC9jyZEs6OomepPnejS7tQSdLXHI4kKWVWZnzTFISwBO7IokRfXa4C kAA6KcXodMroIK2ujSy4oa0ANWZlQfEQK6VFBukVPyz51FE3byxAnAU3K0oA1yF0G3YH dF6Q== X-Forwarded-Encrypted: i=1; AJvYcCW6MwGJwnCmqZmj+C71R+HydxVVdI+4BARwgwo3EK31J3H/xe1/0MlcjYdMmVEP+e1bI3kCV6WwsDESE8zIFGQYMW2FhtupADGFjekeg6WPeibcfBxJ8qvGxJIFvuibBQkv/An25wDaXw== X-Gm-Message-State: AOJu0YzZkEVM+fRGeJYBtN+4cNrRWQdWjwct7f/65NBFfI6skiOytoQH 6p2bnKaZ8gtnzVVwmxSjVEeRIex269MeJF8ObAeSh3aLNVZRISjq X-Google-Smtp-Source: AGHT+IEZLYzCsuhSVIJKYHrwwq5iW4GGVezk9GHauRqFhNs1rHp3ewhEGWqubc6GldWG2dBqM8bZvg== X-Received: by 2002:a17:90b:1d82:b0:296:a13c:8f84 with SMTP id pf2-20020a17090b1d8200b00296a13c8f84mr1250435pjb.33.1707484603168; Fri, 09 Feb 2024 05:16:43 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWxM2ydgQESyUHQ+CSJwn5oQ8r7qDl74zOftXmtLBlNQ+huAHMs9px8efhFI8gYBX0NVOgBOlbfX0ZRixgzl1fxUnivF3AJh9iRrXsAfBBWkoxu5GM4eiZc5QXtm3XGS91WRGXnL4ezWAeJKBlcVRGi3CJad63sx/FOe2eWFejn5WHM0u7embCcXxuJifoOQSSxu9jsNYklfc/g1136ZI8tNNI+pgfllFZQ+vgcn8AUS3IVGThilkYs1eAjhG/KHvfXrjOULVjhM6rRK1Xi95yG6+klcNrxbE9KPH+WmXvuKRCYB1W4ZbkoewX/JEy9i1RiwF9ol1XYZ8h03mC5G9p2TrsHlysRbdJu2EGAyA== Received: from met-Virtual-Machine.. ([131.107.1.159]) by smtp.gmail.com with ESMTPSA id sk12-20020a17090b2dcc00b00296540086a5sm1713246pjb.23.2024.02.09.05.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 05:16:42 -0800 (PST) From: meetakshisetiyaoss@gmail.com To: sfrench@samba.org, pc@manguebit.com, ronniesahlberg@gmail.com, sprasad@microsoft.com, nspmangalore@gmail.com, tom@talpey.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, samba-technical@lists.samba.org, bharathsm.hsk@gmail.com Cc: Meetakshi Setiya Subject: [PATCH 3/3] smb: client: retry compound request without reusing lease Date: Fri, 9 Feb 2024 08:15:52 -0500 Message-Id: <20240209131552.471765-3-meetakshisetiyaoss@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240209131552.471765-1-meetakshisetiyaoss@gmail.com> References: <20240209131552.471765-1-meetakshisetiyaoss@gmail.com> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Meetakshi Setiya There is a shortcoming in the current implementation of the file lease mechanism exposed when the lease keys were attempted to be reused for unlink, rename and set_path_size operations for a client. As per MS-SMB2, lease keys are associated with the file name. Linux smb client maintains lease keys with the inode. If the file has any hardlinks, it is possible that the lease for a file be wrongly reused for an operation on the hardlink or vice versa. In these cases, the mentioned compound operations fail with STATUS_INVALID_PARAMETER. This patch adds a fallback to the old mechanism of not sending any lease with these compound operations if the request with lease key fails with STATUS_INVALID_PARAMETER. Resending the same request without lease key should not hurt any functionality, but might impact performance especially in cases where the error is not because of the usage of wrong lease key and we might end up doing an extra roundtrip. Signed-off-by: Meetakshi Setiya --- fs/smb/client/smb2inode.c | 41 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index 69f3442c5b96..c0d099a9e1ee 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -154,6 +154,17 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, } /* if there is an existing lease, reuse it */ + + /* + * note: files with hardlinks cause unexpected behaviour. As per MS-SMB2, + * lease keys are associated with the filepath. We are maintaining lease keys + * with the inode on the client. If the file has hardlinks, it is possible + * that the lease for a file be reused for an operation on its hardlink or + * vice versa. + * As a workaround, send request using an existing lease key and if the server + * returns STATUS_INVALID_PARAMETER, which maps to EINVAL, send the request + * again without the lease. + */ if (dentry) { inode = d_inode(dentry); if (CIFS_I(inode)->lease_granted && server->ops->get_lease_key) { @@ -867,11 +878,20 @@ int smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, struct cifs_sb_info *cifs_sb, struct dentry *dentry) { - return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, + int rc = smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT, ACL_NO_MODE, NULL, &(int){SMB2_OP_DELETE}, 1, NULL, NULL, NULL, dentry); + if (rc == -EINVAL) { + cifs_dbg(FYI, "invalid lease key, resending request without lease"); + rc = smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, + CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT, + ACL_NO_MODE, NULL, + &(int){SMB2_OP_DELETE}, 1, + NULL, NULL, NULL, NULL); + } + return rc; } static int smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon, @@ -912,8 +932,14 @@ int smb2_rename_path(const unsigned int xid, drop_cached_dir_by_name(xid, tcon, from_name, cifs_sb); cifs_get_writable_path(tcon, from_name, FIND_WR_WITH_DELETE, &cfile); - return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, + int rc = smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, co, DELETE, SMB2_OP_RENAME, cfile, source_dentry); + if (rc == -EINVAL) { + cifs_dbg(FYI, "invalid lease key, resending request without lease"); + rc = smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, + co, DELETE, SMB2_OP_RENAME, cfile, NULL); + } + return rc; } int smb2_create_hardlink(const unsigned int xid, @@ -942,11 +968,20 @@ smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, in_iov.iov_base = &eof; in_iov.iov_len = sizeof(eof); cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile); - return smb2_compound_op(xid, tcon, cifs_sb, full_path, + int rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_WRITE_DATA, FILE_OPEN, 0, ACL_NO_MODE, &in_iov, &(int){SMB2_OP_SET_EOF}, 1, cfile, NULL, NULL, dentry); + if (rc == -EINVAL) { + cifs_dbg(FYI, "invalid lease key, resending request without lease"); + rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, + FILE_WRITE_DATA, FILE_OPEN, + 0, ACL_NO_MODE, &in_iov, + &(int){SMB2_OP_SET_EOF}, 1, + cfile, NULL, NULL, NULL); + } + return rc; } int