|
|
14f8ab |
From 462e3988936761317975fd811dd355b81328b60a Mon Sep 17 00:00:00 2001
|
|
|
14f8ab |
From: Amar Tumballi <amarts@redhat.com>
|
|
|
14f8ab |
Date: Thu, 14 Mar 2019 10:04:28 +0530
|
|
|
14f8ab |
Subject: [PATCH 185/192] gfapi: provide an api for setting statedump path
|
|
|
14f8ab |
|
|
|
14f8ab |
Currently for an application using glfsapi to use glusterfs, when a
|
|
|
14f8ab |
statedump is taken, it uses /var/run/gluster dir to dump info.
|
|
|
14f8ab |
|
|
|
14f8ab |
There can be concerns as this directory may be owned by some other
|
|
|
14f8ab |
user, and hence it may fail taking statedump. Such applications
|
|
|
14f8ab |
should have an option to use different path.
|
|
|
14f8ab |
|
|
|
14f8ab |
This patch provides an API to do so.
|
|
|
14f8ab |
|
|
|
14f8ab |
Upstream details:
|
|
|
14f8ab |
> Updates: bz#1689097
|
|
|
14f8ab |
> Change-Id: I8918e002bc823d83614c972b6c738baa04681b23
|
|
|
14f8ab |
> URL: https://review.gluster.org/22364
|
|
|
14f8ab |
|
|
|
14f8ab |
BUG: 1720461
|
|
|
14f8ab |
Change-Id: I6079c8d799f35eaf76e62d259b51573bf561ba5b
|
|
|
14f8ab |
Signed-off-by: Amar Tumballi <amarts@redhat.com>
|
|
|
14f8ab |
Reviewed-on: https://code.engineering.redhat.com/gerrit/173451
|
|
|
14f8ab |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
14f8ab |
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
|
|
|
14f8ab |
---
|
|
|
14f8ab |
api/src/gfapi.aliases | 2 ++
|
|
|
14f8ab |
api/src/gfapi.map | 5 ++++
|
|
|
14f8ab |
api/src/glfs.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
14f8ab |
api/src/glfs.h | 28 +++++++++++++++++++++++
|
|
|
14f8ab |
4 files changed, 98 insertions(+)
|
|
|
14f8ab |
|
|
|
14f8ab |
diff --git a/api/src/gfapi.aliases b/api/src/gfapi.aliases
|
|
|
14f8ab |
index 09c0fd8..8fdf734 100644
|
|
|
14f8ab |
--- a/api/src/gfapi.aliases
|
|
|
14f8ab |
+++ b/api/src/gfapi.aliases
|
|
|
14f8ab |
@@ -195,3 +195,5 @@ _pub_glfs_zerofill_async _glfs_zerofill_async$GFAPI_6.0
|
|
|
14f8ab |
_pub_glfs_copy_file_range _glfs_copy_file_range$GFAPI_6.0
|
|
|
14f8ab |
_pub_glfs_fsetattr _glfs_fsetattr$GFAPI_6.0
|
|
|
14f8ab |
_pub_glfs_setattr _glfs_setattr$GFAPI_6.0
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+_pub_glfs_set_statedump_path _glfs_set_statedump_path@GFAPI_future
|
|
|
14f8ab |
diff --git a/api/src/gfapi.map b/api/src/gfapi.map
|
|
|
14f8ab |
index b97a614..cf118e8 100644
|
|
|
14f8ab |
--- a/api/src/gfapi.map
|
|
|
14f8ab |
+++ b/api/src/gfapi.map
|
|
|
14f8ab |
@@ -271,3 +271,8 @@ GFAPI_PRIVATE_6.1 {
|
|
|
14f8ab |
global:
|
|
|
14f8ab |
glfs_setfspid;
|
|
|
14f8ab |
} GFAPI_6.0;
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+GFAPI_future {
|
|
|
14f8ab |
+ global:
|
|
|
14f8ab |
+ glfs_set_statedump_path;
|
|
|
14f8ab |
+} GFAPI_PRIVATE_6.1;
|
|
|
14f8ab |
diff --git a/api/src/glfs.c b/api/src/glfs.c
|
|
|
14f8ab |
index f4a8e08..ba513e6 100644
|
|
|
14f8ab |
--- a/api/src/glfs.c
|
|
|
14f8ab |
+++ b/api/src/glfs.c
|
|
|
14f8ab |
@@ -1212,6 +1212,7 @@ glusterfs_ctx_destroy(glusterfs_ctx_t *ctx)
|
|
|
14f8ab |
glusterfs_graph_destroy_residual(trav_graph);
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
+ GF_FREE(ctx->statedump_path);
|
|
|
14f8ab |
FREE(ctx);
|
|
|
14f8ab |
|
|
|
14f8ab |
return ret;
|
|
|
14f8ab |
@@ -1738,3 +1739,65 @@ invalid_fs:
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_unregister, 3.13.0);
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+int
|
|
|
14f8ab |
+pub_glfs_set_statedump_path(struct glfs *fs, const char *path)
|
|
|
14f8ab |
+{
|
|
|
14f8ab |
+ struct stat st;
|
|
|
14f8ab |
+ int ret;
|
|
|
14f8ab |
+ DECLARE_OLD_THIS;
|
|
|
14f8ab |
+ __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ if (!path) {
|
|
|
14f8ab |
+ gf_log("glfs", GF_LOG_ERROR, "path is NULL");
|
|
|
14f8ab |
+ errno = EINVAL;
|
|
|
14f8ab |
+ goto err;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ /* If path is not present OR, if it is directory AND has enough permission
|
|
|
14f8ab |
+ * to create files, then proceed */
|
|
|
14f8ab |
+ ret = sys_stat(path, &st);
|
|
|
14f8ab |
+ if (ret && errno != ENOENT) {
|
|
|
14f8ab |
+ gf_log("glfs", GF_LOG_ERROR, "%s: not a valid path (%s)", path,
|
|
|
14f8ab |
+ strerror(errno));
|
|
|
14f8ab |
+ errno = EINVAL;
|
|
|
14f8ab |
+ goto err;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ if (!ret) {
|
|
|
14f8ab |
+ /* file is present, now check other things */
|
|
|
14f8ab |
+ if (!S_ISDIR(st.st_mode)) {
|
|
|
14f8ab |
+ gf_log("glfs", GF_LOG_ERROR, "%s: path is not directory", path);
|
|
|
14f8ab |
+ errno = EINVAL;
|
|
|
14f8ab |
+ goto err;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+ if (sys_access(path, W_OK | X_OK) < 0) {
|
|
|
14f8ab |
+ gf_log("glfs", GF_LOG_ERROR,
|
|
|
14f8ab |
+ "%s: path doesn't have write permission", path);
|
|
|
14f8ab |
+ errno = EPERM;
|
|
|
14f8ab |
+ goto err;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ /* If set, it needs to be freed, so we don't have leak */
|
|
|
14f8ab |
+ GF_FREE(fs->ctx->statedump_path);
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ fs->ctx->statedump_path = gf_strdup(path);
|
|
|
14f8ab |
+ if (!fs->ctx->statedump_path) {
|
|
|
14f8ab |
+ gf_log("glfs", GF_LOG_ERROR,
|
|
|
14f8ab |
+ "%s: failed to set statedump path, no memory", path);
|
|
|
14f8ab |
+ errno = ENOMEM;
|
|
|
14f8ab |
+ goto err;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ __GLFS_EXIT_FS;
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ return 0;
|
|
|
14f8ab |
+err:
|
|
|
14f8ab |
+ __GLFS_EXIT_FS;
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+invalid_fs:
|
|
|
14f8ab |
+ return -1;
|
|
|
14f8ab |
+}
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_statedump_path, future);
|
|
|
14f8ab |
diff --git a/api/src/glfs.h b/api/src/glfs.h
|
|
|
14f8ab |
index 6714782..a6c12e1 100644
|
|
|
14f8ab |
--- a/api/src/glfs.h
|
|
|
14f8ab |
+++ b/api/src/glfs.h
|
|
|
14f8ab |
@@ -1453,5 +1453,33 @@ int
|
|
|
14f8ab |
glfs_setattr(struct glfs *fs, const char *path, struct glfs_stat *stat,
|
|
|
14f8ab |
int follow) __THROW GFAPI_PUBLIC(glfs_setattr, 6.0);
|
|
|
14f8ab |
|
|
|
14f8ab |
+/*
|
|
|
14f8ab |
+ SYNOPSIS
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ glfs_set_statedump_path: Function to set statedump path.
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ DESCRIPTION
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ This function is used to set statedump directory
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ PARAMETERS
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ @fs: The 'virtual mount' object to be configured with the volume
|
|
|
14f8ab |
+ specification file.
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ @path: statedump path. Should be a directory. But the API won't fail if the
|
|
|
14f8ab |
+ directory doesn't exist yet, as one may create it later.
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ RETURN VALUES
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ 0 : Success.
|
|
|
14f8ab |
+ -1 : Failure. @errno will be set with the type of failure.
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ */
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+int
|
|
|
14f8ab |
+glfs_set_statedump_path(struct glfs *fs, const char *path) __THROW
|
|
|
14f8ab |
+ GFAPI_PUBLIC(glfs_set_statedump_path, future);
|
|
|
14f8ab |
+
|
|
|
14f8ab |
__END_DECLS
|
|
|
14f8ab |
#endif /* !_GLFS_H */
|
|
|
14f8ab |
--
|
|
|
14f8ab |
1.8.3.1
|
|
|
14f8ab |
|