summaryrefslogtreecommitdiffstats
path: root/api/src
diff options
context:
space:
mode:
Diffstat (limited to 'api/src')
-rw-r--r--api/src/gfapi.aliases2
-rw-r--r--api/src/gfapi.map5
-rw-r--r--api/src/glfs.c63
-rw-r--r--api/src/glfs.h28
4 files changed, 98 insertions, 0 deletions
diff --git a/api/src/gfapi.aliases b/api/src/gfapi.aliases
index 09c0fd8f648..8fdf734458f 100644
--- a/api/src/gfapi.aliases
+++ b/api/src/gfapi.aliases
@@ -195,3 +195,5 @@ _pub_glfs_zerofill_async _glfs_zerofill_async$GFAPI_6.0
_pub_glfs_copy_file_range _glfs_copy_file_range$GFAPI_6.0
_pub_glfs_fsetattr _glfs_fsetattr$GFAPI_6.0
_pub_glfs_setattr _glfs_setattr$GFAPI_6.0
+
+_pub_glfs_set_statedump_path _glfs_set_statedump_path@GFAPI_future
diff --git a/api/src/gfapi.map b/api/src/gfapi.map
index b97a614c13d..cf118e8ebe1 100644
--- a/api/src/gfapi.map
+++ b/api/src/gfapi.map
@@ -271,3 +271,8 @@ GFAPI_PRIVATE_6.1 {
global:
glfs_setfspid;
} GFAPI_6.0;
+
+GFAPI_future {
+ global:
+ glfs_set_statedump_path;
+} GFAPI_PRIVATE_6.1;
diff --git a/api/src/glfs.c b/api/src/glfs.c
index f26affbd475..b0db8664416 100644
--- a/api/src/glfs.c
+++ b/api/src/glfs.c
@@ -1211,6 +1211,7 @@ glusterfs_ctx_destroy(glusterfs_ctx_t *ctx)
glusterfs_graph_destroy_residual(trav_graph);
}
+ GF_FREE(ctx->statedump_path);
FREE(ctx);
return ret;
@@ -1737,3 +1738,65 @@ invalid_fs:
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_unregister, 3.13.0);
+
+int
+pub_glfs_set_statedump_path(struct glfs *fs, const char *path)
+{
+ struct stat st;
+ int ret;
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);
+
+ if (!path) {
+ gf_log("glfs", GF_LOG_ERROR, "path is NULL");
+ errno = EINVAL;
+ goto err;
+ }
+
+ /* If path is not present OR, if it is directory AND has enough permission
+ * to create files, then proceed */
+ ret = sys_stat(path, &st);
+ if (ret && errno != ENOENT) {
+ gf_log("glfs", GF_LOG_ERROR, "%s: not a valid path (%s)", path,
+ strerror(errno));
+ errno = EINVAL;
+ goto err;
+ }
+
+ if (!ret) {
+ /* file is present, now check other things */
+ if (!S_ISDIR(st.st_mode)) {
+ gf_log("glfs", GF_LOG_ERROR, "%s: path is not directory", path);
+ errno = EINVAL;
+ goto err;
+ }
+ if (sys_access(path, W_OK | X_OK) < 0) {
+ gf_log("glfs", GF_LOG_ERROR,
+ "%s: path doesn't have write permission", path);
+ errno = EPERM;
+ goto err;
+ }
+ }
+
+ /* If set, it needs to be freed, so we don't have leak */
+ GF_FREE(fs->ctx->statedump_path);
+
+ fs->ctx->statedump_path = gf_strdup(path);
+ if (!fs->ctx->statedump_path) {
+ gf_log("glfs", GF_LOG_ERROR,
+ "%s: failed to set statedump path, no memory", path);
+ errno = ENOMEM;
+ goto err;
+ }
+
+ __GLFS_EXIT_FS;
+
+ return 0;
+err:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
+ return -1;
+}
+
+GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_statedump_path, future);
diff --git a/api/src/glfs.h b/api/src/glfs.h
index 671478206b8..a6c12e128df 100644
--- a/api/src/glfs.h
+++ b/api/src/glfs.h
@@ -1453,5 +1453,33 @@ int
glfs_setattr(struct glfs *fs, const char *path, struct glfs_stat *stat,
int follow) __THROW GFAPI_PUBLIC(glfs_setattr, 6.0);
+/*
+ SYNOPSIS
+
+ glfs_set_statedump_path: Function to set statedump path.
+
+ DESCRIPTION
+
+ This function is used to set statedump directory
+
+ PARAMETERS
+
+ @fs: The 'virtual mount' object to be configured with the volume
+ specification file.
+
+ @path: statedump path. Should be a directory. But the API won't fail if the
+ directory doesn't exist yet, as one may create it later.
+
+ RETURN VALUES
+
+ 0 : Success.
+ -1 : Failure. @errno will be set with the type of failure.
+
+ */
+
+int
+glfs_set_statedump_path(struct glfs *fs, const char *path) __THROW
+ GFAPI_PUBLIC(glfs_set_statedump_path, future);
+
__END_DECLS
#endif /* !_GLFS_H */