vfs_gpfs: Check for GPFS file system on connect
authorChristof Schmitt <cs@samba.org>
Tue, 18 Sep 2018 00:09:16 +0000 (17:09 -0700)
committerChristof Schmitt <cs@samba.org>
Tue, 18 Sep 2018 22:54:23 +0000 (00:54 +0200)
The vfs_gpfs modules uses GPFS API calls that only succeed when using
the module with the GPFS file system. Add an explicit statfs check for
the file system type on connect, to make it obvious when the file system
is missing or not mounted. The check can be skipped by setting
gpfs:check_fstype to 'no'.

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/modules/vfs_gpfs.c

index 982dc19e785fb58a1e97cccfd3e6b5771afdcc77..3a75efdf5e61e26711f780b5fb5ea97ddfd14915 100644 (file)
@@ -2078,6 +2078,7 @@ static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
 {
        struct gpfs_config_data *config;
        int ret;
+       bool check_fstype;
 
        gpfswrap_lib_init(0);
 
@@ -2094,6 +2095,31 @@ static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
                return ret;
        }
 
+       check_fstype = lp_parm_bool(SNUM(handle->conn), "gpfs",
+                                   "check_fstype", true);
+
+       if (check_fstype && !IS_IPC(handle->conn)) {
+               const char *connectpath = handle->conn->connectpath;
+               struct statfs buf = { 0 };
+
+               ret = statfs(connectpath, &buf);
+               if (ret != 0) {
+                       DBG_ERR("statfs failed for share %s at path %s: %s\n",
+                               service, connectpath, strerror(errno));
+                       TALLOC_FREE(config);
+                       return ret;
+               }
+
+               if (buf.f_type != GPFS_SUPER_MAGIC) {
+                       DBG_ERR("SMB share %s, path %s not in GPFS file system."
+                               " statfs magic: 0x%lx\n",
+                               service, connectpath, buf.f_type);
+                       errno = EINVAL;
+                       TALLOC_FREE(config);
+                       return -1;
+               }
+       }
+
        ret = smbacl4_get_vfs_params(handle->conn, &config->nfs4_params);
        if (ret < 0) {
                TALLOC_FREE(config);