Re: [PATCH v4 04/11] cifs: add witness mount option and data structs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Updated to support new mount API (rebased on Ronnie's patch series).
Let me know if you see any problems.


On Mon, Nov 30, 2020 at 12:04 PM Samuel Cabrero <scabrero@xxxxxxx> wrote:
>
> Add 'witness' mount option to register for witness notifications.
>
> Signed-off-by: Samuel Cabrero <scabrero@xxxxxxx>
> ---
>  fs/cifs/cifsfs.c   |  5 +++++
>  fs/cifs/cifsglob.h |  4 ++++
>  fs/cifs/connect.c  | 35 ++++++++++++++++++++++++++++++++++-
>  3 files changed, 43 insertions(+), 1 deletion(-)
>
> diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
> index 8111d0109a2e..c2bbc444b463 100644
> --- a/fs/cifs/cifsfs.c
> +++ b/fs/cifs/cifsfs.c
> @@ -637,6 +637,11 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
>                 seq_printf(s, ",multichannel,max_channels=%zu",
>                            tcon->ses->chan_max);
>
> +#ifdef CONFIG_CIFS_SWN_UPCALL
> +       if (tcon->use_witness)
> +               seq_puts(s, ",witness");
> +#endif
> +
>         return 0;
>  }
>
> diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
> index 484ec2d8c5c9..f45b7c0fbceb 100644
> --- a/fs/cifs/cifsglob.h
> +++ b/fs/cifs/cifsglob.h
> @@ -619,6 +619,7 @@ struct smb_vol {
>         unsigned int max_channels;
>         __u16 compression; /* compression algorithm 0xFFFF default 0=disabled */
>         bool rootfs:1; /* if it's a SMB root file system */
> +       bool witness:1; /* use witness protocol */
>  };
>
>  /**
> @@ -1177,6 +1178,9 @@ struct cifs_tcon {
>         int remap:2;
>         struct list_head ulist; /* cache update list */
>  #endif
> +#ifdef CONFIG_CIFS_SWN_UPCALL
> +       bool use_witness:1; /* use witness protocol */
> +#endif
>  };
>
>  /*
> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> index a938371af6ef..22d46c8acc7f 100644
> --- a/fs/cifs/connect.c
> +++ b/fs/cifs/connect.c
> @@ -102,7 +102,7 @@ enum {
>         Opt_resilient, Opt_noresilient,
>         Opt_domainauto, Opt_rdma, Opt_modesid, Opt_rootfs,
>         Opt_multichannel, Opt_nomultichannel,
> -       Opt_compress,
> +       Opt_compress, Opt_witness,
>
>         /* Mount options which take numeric value */
>         Opt_backupuid, Opt_backupgid, Opt_uid,
> @@ -276,6 +276,7 @@ static const match_table_t cifs_mount_option_tokens = {
>         { Opt_ignore, "relatime" },
>         { Opt_ignore, "_netdev" },
>         { Opt_rootfs, "rootfs" },
> +       { Opt_witness, "witness" },
>
>         { Opt_err, NULL }
>  };
> @@ -1540,6 +1541,13 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
>                         vol->rootfs = true;
>  #endif
>                         break;
> +               case Opt_witness:
> +#ifndef CONFIG_CIFS_SWN_UPCALL
> +                       cifs_dbg(VFS, "Witness support needs CONFIG_CIFS_SWN_UPCALL kernel config option set\n");
> +                       goto cifs_parse_mount_err;
> +#endif
> +                       vol->witness = true;
> +                       break;
>                 case Opt_posixpaths:
>                         vol->posix_paths = 1;
>                         break;
> @@ -3160,6 +3168,8 @@ cifs_put_tcon(struct cifs_tcon *tcon)
>                 return;
>         }
>
> +       /* TODO witness unregister */
> +
>         list_del_init(&tcon->tcon_list);
>         spin_unlock(&cifs_tcp_ses_lock);
>
> @@ -3321,6 +3331,26 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)
>                 tcon->use_resilient = true;
>         }
>
> +#ifdef CONFIG_CIFS_SWN_UPCALL
> +       tcon->use_witness = false;
> +       if (volume_info->witness) {
> +               if (ses->server->vals->protocol_id >= SMB30_PROT_ID) {
> +                       if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) {
> +                               /* TODO witness register */
> +                               tcon->use_witness = true;
> +                       } else {
> +                               cifs_dbg(VFS, "witness requested on mount but no CLUSTER capability on share\n");
> +                               rc = -EOPNOTSUPP;
> +                               goto out_fail;
> +                       }
> +               } else {
> +                       cifs_dbg(VFS, "SMB3 or later required for witness option\n");
> +                       rc = -EOPNOTSUPP;
> +                       goto out_fail;
> +               }
> +       }
> +#endif
> +
>         /* If the user really knows what they are doing they can override */
>         if (tcon->share_flags & SMB2_SHAREFLAG_NO_CACHING) {
>                 if (volume_info->cache_ro)
> @@ -5072,6 +5102,9 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
>         vol_info->sectype = master_tcon->ses->sectype;
>         vol_info->sign = master_tcon->ses->sign;
>         vol_info->seal = master_tcon->seal;
> +#ifdef CONFIG_CIFS_SWN_UPCALL
> +       vol_info->witness = master_tcon->use_witness;
> +#endif
>
>         rc = cifs_set_vol_auth(vol_info, master_tcon->ses);
>         if (rc) {
> --
> 2.29.2
>


-- 
Thanks,

Steve
From 11de8d5dc0521d7e6782fac8605bb7646d66d7e3 Mon Sep 17 00:00:00 2001
From: Samuel Cabrero <scabrero@xxxxxxx>
Date: Fri, 11 Dec 2020 22:59:29 -0600
Subject: [PATCH] cifs: add witness mount option and data structs

Add 'witness' mount option to register for witness notifications.

Signed-off-by: Samuel Cabrero <scabrero@xxxxxxx>
Signed-off-by: Steve French <stfrench@xxxxxxxxxxxxx>
---
 fs/cifs/cifsfs.c     |  5 +++++
 fs/cifs/cifsglob.h   |  3 +++
 fs/cifs/connect.c    | 25 +++++++++++++++++++++++++
 fs/cifs/fs_context.c |  8 ++++++++
 fs/cifs/fs_context.h |  2 ++
 5 files changed, 43 insertions(+)

diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 5d32561ae2ed..f810b25dfeb8 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -638,6 +638,11 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
 		seq_printf(s, ",multichannel,max_channels=%zu",
 			   tcon->ses->chan_max);
 
+#ifdef CONFIG_CIFS_SWN_UPCALL
+	if (tcon->use_witness)
+		seq_puts(s, ",witness");
+#endif
+
 	return 0;
 }
 
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index b46809260e79..78438102f091 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -1086,6 +1086,9 @@ struct cifs_tcon {
 	int remap:2;
 	struct list_head ulist; /* cache update list */
 #endif
+#ifdef CONFIG_CIFS_SWN_UPCALL
+	bool use_witness:1; /* use witness protocol */
+#endif
 };
 
 /*
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index ec80b6c3e20f..46d4f5469688 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1944,6 +1944,8 @@ cifs_put_tcon(struct cifs_tcon *tcon)
 		return;
 	}
 
+	/* TODO witness unregister */
+
 	list_del_init(&tcon->tcon_list);
 	spin_unlock(&cifs_tcp_ses_lock);
 
@@ -2104,6 +2106,26 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
 		}
 		tcon->use_resilient = true;
 	}
+#ifdef CONFIG_CIFS_SWN_UPCALL
+	tcon->use_witness = false;
+	if (ctx->witness) {
+		if (ses->server->vals->protocol_id >= SMB30_PROT_ID) {
+			if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) {
+				/* TODO witness register */
+				tcon->use_witness = true;
+			} else {
+				/* TODO: try to extend for non-cluster uses (eg multichannel) */
+				cifs_dbg(VFS, "witness requested on mount but no CLUSTER capability on share\n");
+				rc = -EOPNOTSUPP;
+				goto out_fail;
+			}
+		} else {
+			cifs_dbg(VFS, "SMB3 or later required for witness option\n");
+			rc = -EOPNOTSUPP;
+			goto out_fail;
+		}
+	}
+#endif
 
 	/* If the user really knows what they are doing they can override */
 	if (tcon->share_flags & SMB2_SHAREFLAG_NO_CACHING) {
@@ -3856,6 +3878,9 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
 	ctx->sectype = master_tcon->ses->sectype;
 	ctx->sign = master_tcon->ses->sign;
 	ctx->seal = master_tcon->seal;
+#ifdef CONFIG_CIFS_SWN_UPCALL
+	ctx->witness = master_tcon->use_witness;
+#endif
 
 	rc = cifs_set_vol_auth(ctx, master_tcon->ses);
 	if (rc) {
diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c
index 9120d148c5f1..fe5cc60f4393 100644
--- a/fs/cifs/fs_context.c
+++ b/fs/cifs/fs_context.c
@@ -119,6 +119,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = {
 	fsparam_flag("modesid", Opt_modesid),
 	fsparam_flag("rootfs", Opt_rootfs),
 	fsparam_flag("compress", Opt_compress),
+	fsparam_flag("witness", Opt_witness),
 
 	/* Mount options which take numeric value */
 	fsparam_u32("backupuid", Opt_backupuid),
@@ -1004,6 +1005,13 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
 		if (cifs_parse_cache_flavor(param->string, ctx) != 0)
 			goto cifs_parse_mount_err;
 		break;
+	case Opt_witness:
+#ifndef CONFIG_CIFS_SWN_UPCALL
+		cifs_dbg(VFS, "Witness support needs CONFIG_CIFS_SWN_UPCALL config option\n");
+			goto cifs_parse_mount_err;
+#endif
+		ctx->witness = true;
+		break;
 	case Opt_rootfs:
 #ifdef CONFIG_CIFS_ROOT
 		ctx->rootfs = true;
diff --git a/fs/cifs/fs_context.h b/fs/cifs/fs_context.h
index d4a905a80883..aaec8a819d34 100644
--- a/fs/cifs/fs_context.h
+++ b/fs/cifs/fs_context.h
@@ -102,6 +102,7 @@ enum cifs_param {
 	Opt_rootfs,
 	Opt_multichannel,
 	Opt_compress,
+	Opt_witness,
 
 	/* Mount options which take numeric value */
 	Opt_backupuid,
@@ -241,6 +242,7 @@ struct smb3_fs_context {
 	unsigned int max_channels;
 	__u16 compression; /* compression algorithm 0xFFFF default 0=disabled */
 	bool rootfs:1; /* if it's a SMB root file system */
+	bool witness:1; /* use witness protocol */
 
 	char *mount_options;
 };
-- 
2.27.0


[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux