From nobody Thu Nov 28 02:34:41 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59D5C17839E; Sun, 6 Oct 2024 10:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208873; cv=none; b=elwDZ+OxfotexymjiGIbeqZGRp+RAvmFwMIaIsdLwl+JkELbfPnhU5TSzu/CjpVW4OVQ4TFAY2RIZrPdGoVySZTYAAMhdprRfJ9ZMS5xB1rESOOP6nbXr6WFl8hlbTwO9JVipvNPBTinwjJ/T6GxOKjgvzZldG8ZYi+j9dW+qiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208873; c=relaxed/simple; bh=kOEasaYZhqGKSFx9kxpk6Zl3ATmAw3rrmXbQDYZOl90=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=emqvmY0+j5aT/QE2LrYWUoPYOf3/8g8MuSKv/wfvp9gbJiT6ZiCgPTGGHg71DV1t5+KMEaw6HCPmuWR3C0WBXETeHsSvosEUceosYr1aJeXlKvtnPJ3bVgj1XUBvp6ymgODIE6ExKNc5c9S8eq4aO6D2bs0SCTtDJdwQ0jZJfJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VlxGLgFY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VlxGLgFY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E980C4CEC5; Sun, 6 Oct 2024 10:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728208872; bh=kOEasaYZhqGKSFx9kxpk6Zl3ATmAw3rrmXbQDYZOl90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VlxGLgFY/LxlnoWpD8k6vPI0CvZBEebvwDUYYlidbU/BHWT4tZJfN4E43eU07/V9f ldRt+YxKNyEdf/t/Ui635qwIGj1eCTigWUMW6N107+grJxxSKb5gNJLhqs3n+uk+FX yJnRV4LzJK2hfguR115T+908prm903zEsrqt0Stel6Z/vim+QzYiX64nS3r7SOS3gK c1HTIzXFl60nl3SMXuQrUKL0XDHfwOvUWq92lHzh4EdgBbU6XLIQHQzgiEaG3jg3Vm FpN8n7FOXEQYkpmwFl0ZEQYahtQBZwl7vMj/qdZOuj1/tLbyZMO1bwKarRClhAs6jz wc+swRFi+tq2Q== Received: by pali.im (Postfix) id CECB5C84; Sun, 6 Oct 2024 12:01:02 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] cifs: Add support for creating NFS-style symlinks Date: Sun, 6 Oct 2024 12:00:43 +0200 Message-Id: <20241006100046.30772-5-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241006100046.30772-1-pali@kernel.org> References: <20241006100046.30772-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable CIFS client is currently able to parse NFS-style symlinks, but is not able to create them. This functionality is useful when the mounted SMB share is used also by Windows NFS server (on Windows Server 2012 or new). It allows interop of symlinks between SMB share mounted by Linux CIFS client and same export from Windows NFS server mounted by some NFS client. New symlinks would be created in NFS-style only in case the mount option -o reparse=3Dnfs is specified, which is not by default. So default CIFS mounts are not affected by this change. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/reparse.c | 47 ++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index f1488f870320..41f91613e7f2 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -410,6 +410,8 @@ static int create_native_socket(const unsigned int xid,= struct inode *inode, =20 static int nfs_set_reparse_buf(struct reparse_posix_data *buf, mode_t mode, dev_t dev, + __le16 *symname_utf16, + int symname_utf16_len, struct kvec *iov) { u64 type; @@ -420,13 +422,18 @@ static int nfs_set_reparse_buf(struct reparse_posix_d= ata *buf, switch ((type =3D reparse_mode_nfs_type(mode))) { case NFS_SPECFILE_BLK: case NFS_SPECFILE_CHR: - dlen =3D sizeof(__le64); + dlen =3D 2 * sizeof(__le32); + ((__le32 *)buf->DataBuffer)[0] =3D MAJOR(dev); + ((__le32 *)buf->DataBuffer)[1] =3D MINOR(dev); + break; + case NFS_SPECFILE_LNK: + dlen =3D symname_utf16_len; + memcpy(buf->DataBuffer, symname_utf16, symname_utf16_len); break; case NFS_SPECFILE_FIFO: case NFS_SPECFILE_SOCK: dlen =3D 0; break; - case NFS_SPECFILE_LNK: /* TODO: add support for NFS symlinks */ default: return -EOPNOTSUPP; } @@ -436,8 +443,6 @@ static int nfs_set_reparse_buf(struct reparse_posix_dat= a *buf, buf->InodeType =3D cpu_to_le64(type); buf->ReparseDataLength =3D cpu_to_le16(len + dlen - sizeof(struct reparse_data_buffer)); - *(__le64 *)buf->DataBuffer =3D cpu_to_le64(((u64)MINOR(dev) << 32) | - MAJOR(dev)); iov->iov_base =3D buf; iov->iov_len =3D len + dlen; return 0; @@ -448,21 +453,42 @@ static int mknod_nfs(unsigned int xid, struct inode *= inode, const char *full_path, umode_t mode, dev_t dev, const char *symname) { + struct cifs_sb_info *cifs_sb =3D CIFS_SB(inode->i_sb); struct cifs_open_info_data data; - struct reparse_posix_data *p; + struct reparse_posix_data *p =3D NULL; + __le16 *symname_utf16 =3D NULL; + int symname_utf16_len =3D 0; struct inode *new; struct kvec iov; __u8 buf[sizeof(*p) + sizeof(__le64)]; int rc; =20 - p =3D (struct reparse_posix_data *)buf; - rc =3D nfs_set_reparse_buf(p, mode, dev, &iov); + if (S_ISLNK(mode)) { + symname_utf16 =3D cifs_strndup_to_utf16(symname, strlen(symname), + &symname_utf16_len, + cifs_sb->local_nls, + NO_MAP_UNI_RSVD); + if (!symname_utf16) { + rc =3D -ENOMEM; + goto out; + } + symname_utf16_len -=3D 2; /* symlink is without trailing wide-nul */ + p =3D kzalloc(sizeof(*p) + symname_utf16_len, GFP_KERNEL); + if (!p) { + rc =3D -ENOMEM; + goto out; + } + } else { + p =3D (struct reparse_posix_data *)buf; + } + rc =3D nfs_set_reparse_buf(p, mode, dev, symname_utf16, symname_utf16_len= , &iov); if (rc) - return rc; + goto out; =20 data =3D (struct cifs_open_info_data) { .reparse_point =3D true, .reparse =3D { .tag =3D IO_REPARSE_TAG_NFS, .posix =3D p, }, + .symlink_target =3D kstrdup(symname, GFP_KERNEL), }; =20 new =3D smb2_get_reparse_inode(&data, inode->i_sb, xid, @@ -472,6 +498,11 @@ static int mknod_nfs(unsigned int xid, struct inode *i= node, else rc =3D PTR_ERR(new); cifs_free_open_info(&data); +out: + if (S_ISLNK(mode)) { + kfree(symname_utf16); + kfree(p); + } return rc; } =20 --=20 2.20.1