From patchwork Tue Sep 16 06:05:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 4915011 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C7BFFBEEA5 for ; Tue, 16 Sep 2014 06:06:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 91D652015D for ; Tue, 16 Sep 2014 06:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D3EE20127 for ; Tue, 16 Sep 2014 06:06:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753091AbaIPGGM (ORCPT ); Tue, 16 Sep 2014 02:06:12 -0400 Received: from mail-qg0-f42.google.com ([209.85.192.42]:55445 "EHLO mail-qg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752046AbaIPGGK (ORCPT ); Tue, 16 Sep 2014 02:06:10 -0400 Received: by mail-qg0-f42.google.com with SMTP id q107so5233866qgd.1 for ; Mon, 15 Sep 2014 23:06:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=77zcxV/Q3PDmkr0TYCNKJEw2+PijuQHqz3uXcZPEY9c=; b=YfKvToOK/UsnH79JWKq+u40EnxpAwb2noglohkL+DrmRXB7eXrTuQvMSJm6KPxe+W+ LYCND5nVNnfMSjWqZVSJkmGhlYoYqK8NcBdeRP0WyUAp1D4csK7OzZiZnAW+0B1vhOfk ERctvg5sJC3Boh2inUbfgH0l2WpBAhndsbQKFufr7wWK3sr1zQORzgCcHse6elSpH9N9 eWIlOtG3PLXvdlHFquzVVyOSofyi9RmDi/BMmHYBJ1HPlWRT/MTA+Q0dTN1DznsueqIY zgD7IYd+HVCmEEPoQVM1Y1BVRLjtP3xwh13GKJI83J9uYonb847ZsR+xdbBjvbcBemYC +Aqw== X-Received: by 10.140.97.247 with SMTP id m110mr44897662qge.80.1410847570030; Mon, 15 Sep 2014 23:06:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.32.116 with HTTP; Mon, 15 Sep 2014 23:05:49 -0700 (PDT) In-Reply-To: References: From: Steve French Date: Tue, 16 Sep 2014 01:05:49 -0500 Message-ID: Subject: Re: [PATCH 2/2] [SMB3] Add mfsymlinks support for SMB2.1/SMB3. Part 2 query symlink To: "linux-cifs@vger.kernel.org" Cc: samba-technical , linux-fsdevel Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, T_TVD_MIME_EPI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Updated version of th3 final patch in series attached (which adds query symlink support for smb2.1/smb3). Makes minor correction to error handling (SMB2_close call was in wrong place in some error cases) On Mon, Sep 15, 2014 at 6:39 PM, Steve French wrote: > Adds support on SMB2.1 and SMB3 mounts for emulation of symlinks > via the "Minshall/French" symlink format already used for cifs > mounts when mfsymlinks mount option is used (and also used by Apple). > http://wiki.samba.org/index.php/UNIX_Extensions#Minshall.2BFrench_symlinks > This second patch adds support to query them (recognize them as symlinks > and read them). > > Signed-off-by: Steve French > CC: Stefan Metzmacher > --- > fs/cifs/link.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > fs/cifs/smb2ops.c | 2 ++ > fs/cifs/smb2proto.h | 4 ++++ > 3 files changed, 71 insertions(+) > > diff --git a/fs/cifs/link.c b/fs/cifs/link.c > index 11657f6..cf1113e 100644 > --- a/fs/cifs/link.c > +++ b/fs/cifs/link.c > @@ -399,6 +399,71 @@ cifs_create_mf_symlink(unsigned int xid, struct > cifs_tcon *tcon, > return rc; > } > > +/* > + * SMB 2.1/SMB3 Protocol specific functions > + */ > + > +int > +smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, > + struct cifs_sb_info *cifs_sb, const unsigned char *path, > + char *pbuf, unsigned int *pbytes_read) > +{ > + int rc; > + struct cifs_fid fid; > + struct cifs_open_parms oparms; > + struct cifs_io_parms io_parms; > + int buf_type = CIFS_NO_BUFFER; > + __le16 *utf16_path; > + __u8 oplock = SMB2_OPLOCK_LEVEL_II; > + struct smb2_file_all_info *pfile_info = NULL; > + > + oparms.tcon = tcon; > + oparms.cifs_sb = cifs_sb; > + oparms.desired_access = GENERIC_READ; > + oparms.create_options = CREATE_NOT_DIR; > + if (backup_cred(cifs_sb)) > + oparms.create_options |= CREATE_OPEN_BACKUP_INTENT; > + oparms.disposition = FILE_OPEN; > + oparms.fid = &fid; > + oparms.reconnect = false; > + > + utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); > + if (utf16_path == NULL) > + return -ENOMEM; > + > + pfile_info = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, > + GFP_KERNEL); > + > + if (pfile_info == NULL) { > + rc = -ENOMEM; > + goto qmf_out; > + } > + > + rc = SMB2_open(xid, &oparms, utf16_path, &oplock, pfile_info, NULL); > + if (rc) > + goto qmf_out; > + > + if (pfile_info->EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) { > + /* it's not a symlink */ > + rc = -ENOENT; /* Is there a better rc to return? */ > + goto qmf_out; > + } > + > + io_parms.netfid = fid.netfid; > + io_parms.pid = current->tgid; > + io_parms.tcon = tcon; > + io_parms.offset = 0; > + io_parms.length = CIFS_MF_SYMLINK_FILE_SIZE; > + io_parms.persistent_fid = fid.persistent_fid; > + io_parms.volatile_fid = fid.volatile_fid; > + rc = SMB2_read(xid, &io_parms, pbytes_read, &pbuf, &buf_type); > +qmf_out: > + kfree(utf16_path); > + kfree(pfile_info); > + SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); > + return rc; > +} > + > int > smb3_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, > struct cifs_sb_info *cifs_sb, const unsigned char *path, > diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c > index 7d3fa29..489f48b 100644 > --- a/fs/cifs/smb2ops.c > +++ b/fs/cifs/smb2ops.c > @@ -1452,6 +1452,7 @@ struct smb_version_operations smb21_operations = { > .rename = smb2_rename_path, > .create_hardlink = smb2_create_hardlink, > .query_symlink = smb2_query_symlink, > + .query_mf_symlink = smb3_query_mf_symlink, > .create_mf_symlink = smb3_create_mf_symlink, > .open = smb2_open_file, > .set_fid = smb2_set_fid, > @@ -1532,6 +1533,7 @@ struct smb_version_operations smb30_operations = { > .rename = smb2_rename_path, > .create_hardlink = smb2_create_hardlink, > .query_symlink = smb2_query_symlink, > + .query_mf_symlink = smb3_query_mf_symlink, > .create_mf_symlink = smb3_create_mf_symlink, > .open = smb2_open_file, > .set_fid = smb2_set_fid, > diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h > index e144ecf..79dc650 100644 > --- a/fs/cifs/smb2proto.h > +++ b/fs/cifs/smb2proto.h > @@ -85,6 +85,10 @@ extern int smb2_create_hardlink(const unsigned int > xid, struct cifs_tcon *tcon, > extern int smb3_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, > struct cifs_sb_info *cifs_sb, const unsigned char *path, > char *pbuf, unsigned int *pbytes_written); > +extern int smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, > + struct cifs_sb_info *cifs_sb, > + const unsigned char *path, char *pbuf, > + unsigned int *pbytes_read); > extern int smb2_open_file(const unsigned int xid, > struct cifs_open_parms *oparms, > __u32 *oplock, FILE_ALL_INFO *buf); > -- > > -- > Thanks, > > Steve From d4493f4e3c86aabf9c94717f87763d13ec431394 Mon Sep 17 00:00:00 2001 From: Steve French Date: Tue, 16 Sep 2014 00:58:26 -0500 Subject: [PATCH] [SMB3] mfsymlinks support for SMB2.1/SMB3. Part 2 query symlink Adds support on SMB2.1 and SMB3 mounts for emulation of symlinks via the "Minshall/French" symlink format already used for cifs mounts when mfsymlinks mount option is used (and also used by Apple). http://wiki.samba.org/index.php/UNIX_Extensions#Minshall.2BFrench_symlinks This second patch adds support to query them (recognize them as symlinks and read them). Second version of patch makes minor correction to error handling. Signed-off-by: Steve French CC: Stefan Metzmacher --- fs/cifs/link.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/smb2ops.c | 2 ++ fs/cifs/smb2proto.h | 4 ++++ 3 files changed, 71 insertions(+) diff --git a/fs/cifs/link.c b/fs/cifs/link.c index 11657f6..de3dad8 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c @@ -399,6 +399,71 @@ cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, return rc; } +/* + * SMB 2.1/SMB3 Protocol specific functions + */ + +int +smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, + struct cifs_sb_info *cifs_sb, const unsigned char *path, + char *pbuf, unsigned int *pbytes_read) +{ + int rc; + struct cifs_fid fid; + struct cifs_open_parms oparms; + struct cifs_io_parms io_parms; + int buf_type = CIFS_NO_BUFFER; + __le16 *utf16_path; + __u8 oplock = SMB2_OPLOCK_LEVEL_II; + struct smb2_file_all_info *pfile_info = NULL; + + oparms.tcon = tcon; + oparms.cifs_sb = cifs_sb; + oparms.desired_access = GENERIC_READ; + oparms.create_options = CREATE_NOT_DIR; + if (backup_cred(cifs_sb)) + oparms.create_options |= CREATE_OPEN_BACKUP_INTENT; + oparms.disposition = FILE_OPEN; + oparms.fid = &fid; + oparms.reconnect = false; + + utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); + if (utf16_path == NULL) + return -ENOMEM; + + pfile_info = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, + GFP_KERNEL); + + if (pfile_info == NULL) { + rc = -ENOMEM; + goto qmf_out; + } + + rc = SMB2_open(xid, &oparms, utf16_path, &oplock, pfile_info, NULL); + if (rc) + goto qmf_out; + + if (pfile_info->EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) { + /* it's not a symlink */ + rc = -ENOENT; /* Is there a better rc to return? */ + goto qmf_out; + } + + io_parms.netfid = fid.netfid; + io_parms.pid = current->tgid; + io_parms.tcon = tcon; + io_parms.offset = 0; + io_parms.length = CIFS_MF_SYMLINK_FILE_SIZE; + io_parms.persistent_fid = fid.persistent_fid; + io_parms.volatile_fid = fid.volatile_fid; + rc = SMB2_read(xid, &io_parms, pbytes_read, &pbuf, &buf_type); + SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); +qmf_out: + kfree(utf16_path); + kfree(pfile_info); + return rc; +} + int smb3_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb, const unsigned char *path, diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 7d3fa29..489f48b 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1452,6 +1452,7 @@ struct smb_version_operations smb21_operations = { .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, .query_symlink = smb2_query_symlink, + .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file, .set_fid = smb2_set_fid, @@ -1532,6 +1533,7 @@ struct smb_version_operations smb30_operations = { .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, .query_symlink = smb2_query_symlink, + .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file, .set_fid = smb2_set_fid, diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h index e144ecf..79dc650 100644 --- a/fs/cifs/smb2proto.h +++ b/fs/cifs/smb2proto.h @@ -85,6 +85,10 @@ extern int smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon, extern int smb3_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb, const unsigned char *path, char *pbuf, unsigned int *pbytes_written); +extern int smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, + struct cifs_sb_info *cifs_sb, + const unsigned char *path, char *pbuf, + unsigned int *pbytes_read); extern int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32 *oplock, FILE_ALL_INFO *buf); -- 1.9.1