From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=DKIM_ADSP_ALL,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0238C4360F for ; Thu, 4 Apr 2019 17:17:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FE7E206BA for ; Thu, 4 Apr 2019 17:17:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=paulo.ac header.i=@paulo.ac header.b="ASKKhKyn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728650AbfDDRRV (ORCPT ); Thu, 4 Apr 2019 13:17:21 -0400 Received: from mail.paulo.ac ([51.15.136.203]:50288 "EHLO mail.paulo.ac" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727152AbfDDRRV (ORCPT ); Thu, 4 Apr 2019 13:17:21 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.paulo.ac (Postfix) with ESMTP id 0D7A11C17C7 for ; Thu, 4 Apr 2019 17:17:17 +0000 (UTC) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "Cc" From: Paulo Alcantara DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=paulo.ac; s=201902; t=1554398236; bh=W9TUw15msX7A7/kf3TeNT+eYBjQsMs6NG8bNg/mYV3E=; h=From:To:Cc:Cc:Subject:In-Reply-To:References:Date:From; b=ASKKhKynK5r980diLGE9wPwbPF6ZmzNEUT/UuhsUPzLRCubky1lU2+0pRjOagA6yf bNNL6QFIofvx48fC++ufQv2kqhB0eP0mftxB385FQqX7T4+ASCjft8+OAb45hQ0gJs ACI+LrGTspisCfSNHqiIGhJqx8GtxrmYzkTWXczZjq2k5ilZYPZE83o2jvPaPY+P7M /vgNO90yYNffbganGLpJkhwK0hx4bNDEC7XDUoYxg363paB5BMGDpkrsN7XqXogY+6 4HNBn7uSzlinYtotWTZWjQN8hf8mCfFGtkfJmwVCEnVdoiuTay8knj7eRJdQEH5gfo AXpo4/h53Gm4Q== To: Pavel Shilovsky , Ronnie Sahlberg , =?utf-8?Q?Aur=C3=A9lien?= Aptel , Steve French Cc: linux-cifs Subject: Re: current patches for cifs-utils release In-Reply-To: References: Date: Thu, 04 Apr 2019 14:16:54 -0300 Message-ID: <875zrtg06x.fsf@paulo.ac> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, Pavel Shilovsky writes: > Hi all, > > for-next branch is updated with the patches in attachments (resulting > of merging some of the patches and fixing up some minor style > problems): > > https://github.com/piastry/cifs-utils/commits/next > > Please take a look if anything is missed. Looks good to me. Thanks! Reviewed-by: Paulo Alcantara cheers, Paulo > > -- > Best regards, > Pavel Shilovsky > From 7cf164b0fbddcc343226df7e096ecd82080f3350 Mon Sep 17 00:00:00 2001 > From: Steve French > Date: Fri, 29 Mar 2019 03:05:55 -0500 > Subject: [PATCH 1/7] smbinfo: Add ability to query snapshots (previous > versions) > > "smbinfo list-snapshots" > > Signed-off-by: Steve French > Signed-off-by: Pavel Shilovsky > --- > smbinfo.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++- > smbinfo.rst | 2 ++ > 2 files changed, 109 insertions(+), 1 deletion(-) > > diff --git a/smbinfo.c b/smbinfo.c > index 33fca95..adfd85e 100644 > --- a/smbinfo.c > +++ b/smbinfo.c > @@ -89,6 +89,8 @@ usage(char *name) > " Prints the security descriptor for a cifs file.\n" > " quota:\n" > " Prints the quota for a cifs file.\n" > + " list-snapshots:\n" > + " List the previous versions of the volume that backs this file.\= n" > " fsctl-getobjid:\n" > " Prints the objectid of the file and GUID of the underlying volu= me.\n", > name); > @@ -882,7 +884,6 @@ print_quota(unsigned char *sd) > uint32_t u32, neo; > uint64_t u64; > struct timeval tv; > - struct tm; > int i, off =3D 0; >=20=20 > one_more: > @@ -966,6 +967,109 @@ quota(int f) > free(qi); > } >=20=20 > + > +struct smb_snapshot_array { > + int32_t number_of_snapshots; > + int32_t number_of_snapshots_returned; > + int32_t snapshot_array_size; > + char snapshot_data[0]; > +}; > + > + > +#define GMT_NAME_LEN 24 /* length of a @GMT- name */ > +#define GMT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S" > + > +#define NTFS_TIME_OFFSET ((unsigned long long)(369*365 + 89) * 24 * 3600= * 10000000) > + > +static void print_snapshots(struct smb_snapshot_array *psnap) > +{ > + int current_snapshot_entry =3D 0; > + char gmt_token[GMT_NAME_LEN + 1] =3D {0}; > + int i; > + int j =3D 0; > + struct tm tm; > + unsigned long long dce_time; > + > + printf("Number of snapshots: %d Number of snapshots returned: %d\n", > + psnap->number_of_snapshots, > + psnap->number_of_snapshots_returned); > + printf("Snapshot list in GMT (Coordinated UTC Time) and SMB format (100= nanosecond units needed for snapshot mounts):"); > + for (i =3D 0; i < psnap->snapshot_array_size; i++) { > + if (psnap->snapshot_data[i] =3D=3D '@') { > + j =3D 0; > + current_snapshot_entry++; > + printf("\n%d) GMT:", current_snapshot_entry); > + } > + if (psnap->snapshot_data[i] !=3D 0) { > + gmt_token[j] =3D psnap->snapshot_data[i]; > + j++; > + } > + if (j =3D=3D GMT_NAME_LEN) { > + printf("%s", gmt_token); > + j =3D 0; > + strptime(gmt_token, GMT_FORMAT, &tm); > + dce_time =3D timegm(&tm) * 10000000 + NTFS_TIME_OFFSET; > + printf("\n SMB3:%llu", dce_time); > + } > + } > + printf("\n"); > +} > + > +#define CIFS_ENUMERATE_SNAPSHOTS _IOR(CIFS_IOCTL_MAGIC, 6, struct smb_sn= apshot_array) > + > +#define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */ > + > +static void > +list_snapshots(int f) > +{ > + > + struct smb_snapshot_array snap_inf; > + struct smb_snapshot_array *buf; > + > + /* > + * When first field in structure we pass in here is zero, cifs.ko can > + * recognize that this is the first query and that it must set the SMB3 > + * FSCTL response buffer size (in the request) to exactly 16 bytes > + * (which is required by some servers to process the initial query) > + */ > + snap_inf.number_of_snapshots =3D 0; > + snap_inf.number_of_snapshots_returned =3D 0; > + snap_inf.snapshot_array_size =3D sizeof(struct smb_snapshot_array); > + > + /* Query the number of snapshots so we know how much to allocate */ > + if (ioctl(f, CIFS_ENUMERATE_SNAPSHOTS, &snap_inf) < 0) { > + fprintf(stderr, "Querying snapshots failed with %s\n", strerror(errno)= ); > + exit(1); > + } > + > + if (snap_inf.number_of_snapshots =3D=3D 0) > + return; > + > + /* Now that we know the size, query the list from the server */ > + > + buf =3D malloc(snap_inf.snapshot_array_size + MIN_SNAPSHOT_ARRAY_SIZE); > + > + if (buf =3D=3D NULL) { > + printf("Failed, out of memory.\n"); > + exit(1); > + } > + /* > + * first parm is non-zero which allows cifs.ko to recognize that this is > + * the second query (it has to set response buf size larger) > + */ > + buf->number_of_snapshots =3D snap_inf.number_of_snapshots; > + > + buf->snapshot_array_size =3D snap_inf.snapshot_array_size; > + > + if (ioctl(f, CIFS_ENUMERATE_SNAPSHOTS, buf) < 0) { > + fprintf(stderr, "Querying snapshots failed with %s\n", strerror(errno)= ); > + exit(1); > + } > + > + print_snapshots(buf); > + free(buf); > +} > + > int main(int argc, char *argv[]) > { > int c; > @@ -1016,6 +1120,8 @@ int main(int argc, char *argv[]) > secdesc(f); > else if (!strcmp(argv[optind], "quota")) > quota(f); > + else if (!strcmp(argv[optind], "list-snapshots")) > + list_snapshots(f); > else if (!strcmp(argv[1], "fsctl-getobjid")) > fsctlgetobjid(f); > else { > diff --git a/smbinfo.rst b/smbinfo.rst > index fd7f0ff..0c96050 100644 > --- a/smbinfo.rst > +++ b/smbinfo.rst > @@ -64,6 +64,8 @@ COMMAND >=20=20 > `fsctl-getobjid`: Prints the ObjectID >=20=20 > +`list-snapshots`: Lists the previous versions of the volume that backs t= his file > + > `quota`: Print the quota for the volume in the form > - SID Length > - Change Time > --=20 > 2.7.4 > > From e8b8bb5fa61c53b05975650194da24786c4a4f32 Mon Sep 17 00:00:00 2001 > From: Pavel Shilovsky > Date: Wed, 3 Apr 2019 22:42:10 +0000 > Subject: [PATCH 5/7] mount.cifs: detect GMT format of snapshot version > > In order to provide an easy way to access snapshots a GMT > token string should be allowed as a "snapshot" mount option > argument, not SMB 100-nanoseconds time only. Detect if the > argument is in GMT format and convert it to SMB 100-nanoseconds > time before passing to the kernel. > > Signed-off-by: Pavel Shilovsky > --- > mount.cifs.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 47 insertions(+), 7 deletions(-) > > diff --git a/mount.cifs.c b/mount.cifs.c > index c6a1bd6..b3235e4 100644 > --- a/mount.cifs.c > +++ b/mount.cifs.c > @@ -43,6 +43,7 @@ > #include > #include > #include > +#include > #include > #include > #ifdef HAVE_SYS_FSUID_H > @@ -161,10 +162,16 @@ > #define OPT_BKUPUID 30 > #define OPT_BKUPGID 31 > #define OPT_NOFAIL 32 > +#define OPT_SNAPSHOT 33 >=20=20 > #define MNT_TMP_FILE "/.mtab.cifs.XXXXXX" >=20=20 > -/* struct for holding parsed mount info for use by privleged process */ > +#define GMT_NAME_LEN 24 /* length of a @GMT- name */ > +#define GMT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S" > + > +#define NTFS_TIME_OFFSET ((unsigned long long)(369*365 + 89) * 24 * 3600= * 10000000) > + > +/* struct for holding parsed mount info for use by privileged process */ > struct parsed_mount_info { > unsigned long flags; > char host[NI_MAXHOST + 1]; > @@ -271,9 +278,9 @@ static int mount_usage(FILE * stream) > fprintf(stream, > "\n\tcache=3D,nounix,cifsacl,sec=3D,"); > fprintf(stream, > - "\n\tsign,seal,fsc,snapshot=3D