summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorArjun <arjsharm@redhat.com>2018-12-04 11:02:37 +0530
committerAmar Tumballi <amarts@redhat.com>2019-01-16 06:24:45 +0000
commit213f31bf9e72eee57a6579b66e259af8e59e9c67 (patch)
treed8b25d80f5e0422a8017deec97c2e3bc9e7d034b /api
parent2261e444a47ffffb5d64305efceee1d5a734cd75 (diff)
gfapi : making glfs_setattr/glfs_fsetattr as public
Initially glfs_fsetattr and glfs_setattr, both functions accepted iatt as arguements but now they accept stat and later in the function the stat is being converted to iatt so that it can be passed to syncop_fsetattr/syncop_setattr. Change-Id: I41a9e0124785a32ca19ef4d492c5ed5002e66ede updates: #389 Signed-off-by: Arjun Sharma <arjsharm@redhat.com>
Diffstat (limited to 'api')
-rw-r--r--api/src/gfapi.aliases4
-rw-r--r--api/src/gfapi.map2
-rw-r--r--api/src/glfs-fops.c118
-rw-r--r--api/src/glfs-handleops.c2
-rw-r--r--api/src/glfs-handles.h10
-rw-r--r--api/src/glfs-internal.h3
-rw-r--r--api/src/glfs.h60
7 files changed, 135 insertions, 64 deletions
diff --git a/api/src/gfapi.aliases b/api/src/gfapi.aliases
index 4cafd1f..f4f0a2c 100644
--- a/api/src/gfapi.aliases
+++ b/api/src/gfapi.aliases
@@ -191,4 +191,6 @@ _pub_glfs_ftruncate _glfs_ftruncate$GFAPI_future
_pub_glfs_ftruncate_async _glfs_ftruncate_async$GFAPI_future
_pub_glfs_discard_async _glfs_discard_async$GFAPI_future
_pub_glfs_zerofill_async _glfs_zerofill_async$GFAPI_future
-_pub_glfs_copy_file_range _glfs_copy_file_range$GFAPI_future \ No newline at end of file
+_pub_glfs_copy_file_range _glfs_copy_file_range$GFAPI_future
+_pub_glfs_fsetattr _glfs_fsetattr$GFAPI_future
+_pub_glfs_setattr _glfs_setattr$GFAPI_future
diff --git a/api/src/gfapi.map b/api/src/gfapi.map
index 332af12..676cd9f 100644
--- a/api/src/gfapi.map
+++ b/api/src/gfapi.map
@@ -262,5 +262,7 @@ GFAPI_future {
glfs_discard_async;
glfs_zerofill_async;
glfs_copy_file_range;
+ glfs_setattr;
+ glfs_fsetattr;
} GFAPI_PRIVATE_future;
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c
index 6d81bd8..c052bae 100644
--- a/api/src/glfs-fops.c
+++ b/api/src/glfs-fops.c
@@ -3914,8 +3914,8 @@ invalid_fs:
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_statvfs, 3.4.0);
int
-glfs_setattr(struct glfs *fs, const char *path, struct iatt *iatt, int valid,
- int follow)
+pub_glfs_setattr(struct glfs *fs, const char *path, struct stat *stat,
+ int valid, int follow)
{
int ret = -1;
xlator_t *subvol = NULL;
@@ -3925,11 +3925,17 @@ glfs_setattr(struct glfs *fs, const char *path, struct iatt *iatt, int valid,
struct iatt riatt = {
0,
};
+ struct iatt iatt = {
+ 0,
+ };
int reval = 0;
+ int glvalid = 0;
DECLARE_OLD_THIS;
__GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);
+ GF_VALIDATE_OR_GOTO("glfs_setattr", stat, out);
+
subvol = glfs_active_subvol(fs);
if (!subvol) {
ret = -1;
@@ -3947,8 +3953,10 @@ retry:
if (ret)
goto out;
+ glfs_iatt_from_stat(stat, valid, &iatt, &glvalid);
+
/* TODO : Add leaseid */
- ret = syncop_setattr(subvol, &loc, iatt, valid, 0, 0, NULL, NULL);
+ ret = syncop_setattr(subvol, &loc, &iatt, glvalid, 0, 0, NULL, NULL);
DECODE_SYNCOP_ERR(ret);
ESTALE_RETRY(ret, errno, reval, &loc, retry);
@@ -3963,10 +3971,16 @@ invalid_fs:
return ret;
}
+GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setattr, future);
+
int
-glfs_fsetattr(struct glfs_fd *glfd, struct iatt *iatt, int valid)
+pub_glfs_fsetattr(struct glfs_fd *glfd, struct stat *stat, int valid)
{
int ret = -1;
+ int glvalid = 0;
+ struct iatt iatt = {
+ 0,
+ };
xlator_t *subvol = NULL;
fd_t *fd = NULL;
@@ -3975,6 +3989,8 @@ glfs_fsetattr(struct glfs_fd *glfd, struct iatt *iatt, int valid)
GF_REF_GET(glfd);
+ GF_VALIDATE_OR_GOTO("glfs_fsetattr", stat, out);
+
subvol = glfs_active_subvol(glfd->fs);
if (!subvol) {
ret = -1;
@@ -3989,8 +4005,10 @@ glfs_fsetattr(struct glfs_fd *glfd, struct iatt *iatt, int valid)
goto out;
}
+ glfs_iatt_from_stat(stat, valid, &iatt, &glvalid);
+
/* TODO : Add leaseid */
- ret = syncop_fsetattr(subvol, fd, iatt, valid, 0, 0, NULL, NULL);
+ ret = syncop_fsetattr(subvol, fd, &iatt, glvalid, 0, 0, NULL, NULL);
DECODE_SYNCOP_ERR(ret);
out:
if (fd)
@@ -4006,19 +4024,21 @@ invalid_fs:
return ret;
}
+GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsetattr, future);
+
int
pub_glfs_chmod(struct glfs *fs, const char *path, mode_t mode)
{
int ret = -1;
- struct iatt iatt = {
+ struct stat stat = {
0,
};
int valid = 0;
- iatt.ia_prot = ia_prot_from_st_mode(mode);
- valid = GF_SET_ATTR_MODE;
+ stat.st_mode = mode;
+ valid = GFAPI_SET_ATTR_MODE;
- ret = glfs_setattr(fs, path, &iatt, valid, 1);
+ ret = glfs_setattr(fs, path, &stat, valid, 1);
return ret;
}
@@ -4029,15 +4049,15 @@ int
pub_glfs_fchmod(struct glfs_fd *glfd, mode_t mode)
{
int ret = -1;
- struct iatt iatt = {
+ struct stat stat = {
0,
};
int valid = 0;
- iatt.ia_prot = ia_prot_from_st_mode(mode);
- valid = GF_SET_ATTR_MODE;
+ stat.st_mode = mode;
+ valid = GFAPI_SET_ATTR_MODE;
- ret = glfs_fsetattr(glfd, &iatt, valid);
+ ret = glfs_fsetattr(glfd, &stat, valid);
return ret;
}
@@ -4049,22 +4069,22 @@ pub_glfs_chown(struct glfs *fs, const char *path, uid_t uid, gid_t gid)
{
int ret = 0;
int valid = 0;
- struct iatt iatt = {
+ struct stat stat = {
0,
};
if (uid != (uid_t)-1) {
- iatt.ia_uid = uid;
- valid = GF_SET_ATTR_UID;
+ stat.st_uid = uid;
+ valid = GFAPI_SET_ATTR_UID;
}
if (gid != (uid_t)-1) {
- iatt.ia_gid = gid;
- valid = valid | GF_SET_ATTR_GID;
+ stat.st_gid = gid;
+ valid = valid | GFAPI_SET_ATTR_GID;
}
if (valid)
- ret = glfs_setattr(fs, path, &iatt, valid, 1);
+ ret = glfs_setattr(fs, path, &stat, valid, 1);
return ret;
}
@@ -4076,22 +4096,22 @@ pub_glfs_lchown(struct glfs *fs, const char *path, uid_t uid, gid_t gid)
{
int ret = 0;
int valid = 0;
- struct iatt iatt = {
+ struct stat stat = {
0,
};
if (uid != (uid_t)-1) {
- iatt.ia_uid = uid;
- valid = GF_SET_ATTR_UID;
+ stat.st_uid = uid;
+ valid = GFAPI_SET_ATTR_UID;
}
if (gid != (uid_t)-1) {
- iatt.ia_gid = gid;
- valid = valid | GF_SET_ATTR_GID;
+ stat.st_gid = gid;
+ valid = valid | GFAPI_SET_ATTR_GID;
}
if (valid)
- ret = glfs_setattr(fs, path, &iatt, valid, 0);
+ ret = glfs_setattr(fs, path, &stat, valid, 0);
return ret;
}
@@ -4103,22 +4123,22 @@ pub_glfs_fchown(struct glfs_fd *glfd, uid_t uid, gid_t gid)
{
int ret = 0;
int valid = 0;
- struct iatt iatt = {
+ struct stat stat = {
0,
};
if (uid != (uid_t)-1) {
- iatt.ia_uid = uid;
- valid = GF_SET_ATTR_UID;
+ stat.st_uid = uid;
+ valid = GFAPI_SET_ATTR_UID;
}
if (gid != (uid_t)-1) {
- iatt.ia_gid = gid;
- valid = valid | GF_SET_ATTR_GID;
+ stat.st_gid = gid;
+ valid = valid | GFAPI_SET_ATTR_GID;
}
if (valid)
- ret = glfs_fsetattr(glfd, &iatt, valid);
+ ret = glfs_fsetattr(glfd, &stat, valid);
return ret;
}
@@ -4131,18 +4151,16 @@ pub_glfs_utimens(struct glfs *fs, const char *path,
{
int ret = -1;
int valid = 0;
- struct iatt iatt = {
+ struct stat stat = {
0,
};
- iatt.ia_atime = times[0].tv_sec;
- iatt.ia_atime_nsec = times[0].tv_nsec;
- iatt.ia_mtime = times[1].tv_sec;
- iatt.ia_mtime_nsec = times[1].tv_nsec;
+ stat.st_atim = times[0];
+ stat.st_mtim = times[1];
- valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME;
+ valid = GFAPI_SET_ATTR_ATIME | GFAPI_SET_ATTR_MTIME;
- ret = glfs_setattr(fs, path, &iatt, valid, 1);
+ ret = glfs_setattr(fs, path, &stat, valid, 1);
return ret;
}
@@ -4155,18 +4173,16 @@ pub_glfs_lutimens(struct glfs *fs, const char *path,
{
int ret = -1;
int valid = 0;
- struct iatt iatt = {
+ struct stat stat = {
0,
};
- iatt.ia_atime = times[0].tv_sec;
- iatt.ia_atime_nsec = times[0].tv_nsec;
- iatt.ia_mtime = times[1].tv_sec;
- iatt.ia_mtime_nsec = times[1].tv_nsec;
+ stat.st_atim = times[0];
+ stat.st_mtim = times[1];
- valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME;
+ valid = GFAPI_SET_ATTR_ATIME | GFAPI_SET_ATTR_MTIME;
- ret = glfs_setattr(fs, path, &iatt, valid, 0);
+ ret = glfs_setattr(fs, path, &stat, valid, 0);
return ret;
}
@@ -4178,18 +4194,16 @@ pub_glfs_futimens(struct glfs_fd *glfd, const struct timespec times[2])
{
int ret = -1;
int valid = 0;
- struct iatt iatt = {
+ struct stat stat = {
0,
};
- iatt.ia_atime = times[0].tv_sec;
- iatt.ia_atime_nsec = times[0].tv_nsec;
- iatt.ia_mtime = times[1].tv_sec;
- iatt.ia_mtime_nsec = times[1].tv_nsec;
+ stat.st_atim = times[0];
+ stat.st_mtim = times[1];
- valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME;
+ valid = GFAPI_SET_ATTR_ATIME | GFAPI_SET_ATTR_MTIME;
- ret = glfs_fsetattr(glfd, &iatt, valid);
+ ret = glfs_fsetattr(glfd, &stat, valid);
return ret;
}
diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c
index 3e4e2fb..d4e1545 100644
--- a/api/src/glfs-handleops.c
+++ b/api/src/glfs-handleops.c
@@ -18,7 +18,7 @@
int
glfs_listxattr_process(void *value, size_t size, dict_t *xattr);
-static void
+void
glfs_iatt_from_stat(struct stat *stat, int valid, struct iatt *iatt,
int *glvalid)
{
diff --git a/api/src/glfs-handles.h b/api/src/glfs-handles.h
index 89b1ed0..f7e6a06 100644
--- a/api/src/glfs-handles.h
+++ b/api/src/glfs-handles.h
@@ -46,16 +46,6 @@
*
*/
-/* Values for valid flags to be used when using XXXsetattr, to set multiple
- attribute values passed via the related stat structure.
- */
-#define GFAPI_SET_ATTR_MODE 0x1
-#define GFAPI_SET_ATTR_UID 0x2
-#define GFAPI_SET_ATTR_GID 0x4
-#define GFAPI_SET_ATTR_SIZE 0x8
-#define GFAPI_SET_ATTR_ATIME 0x10
-#define GFAPI_SET_ATTR_MTIME 0x20
-
/* Handle length for object handles returned from glfs_h_extract_handle or
* glfs_h_create_from_handle */
#define GFAPI_HANDLE_LENGTH 16
diff --git a/api/src/glfs-internal.h b/api/src/glfs-internal.h
index c7fbdeb..6ab28ff 100644
--- a/api/src/glfs-internal.h
+++ b/api/src/glfs-internal.h
@@ -522,6 +522,9 @@ int
glfs_loc_touchup(loc_t *loc) GFAPI_PRIVATE(glfs_loc_touchup, 3.4.0);
void
glfs_iatt_to_stat(struct glfs *fs, struct iatt *iatt, struct stat *stat);
+void
+glfs_iatt_from_stat(struct stat *stat, int valid, struct iatt *iatt,
+ int *gvalid);
int
glfs_loc_link(loc_t *loc, struct iatt *iatt);
int
diff --git a/api/src/glfs.h b/api/src/glfs.h
index fe305e8..9f60756 100644
--- a/api/src/glfs.h
+++ b/api/src/glfs.h
@@ -20,6 +20,17 @@
both the library and the application.
*/
+/* Values for valid flags to be used when using XXXsetattr, to set multiple
+ attribute values passed via the related stat structure.
+ */
+
+#define GFAPI_SET_ATTR_MODE 0x1
+#define GFAPI_SET_ATTR_UID 0x2
+#define GFAPI_SET_ATTR_GID 0x4
+#define GFAPI_SET_ATTR_SIZE 0x8
+#define GFAPI_SET_ATTR_ATIME 0x10
+#define GFAPI_SET_ATTR_MTIME 0x20
+
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
#endif
@@ -1395,5 +1406,54 @@ int
glfs_lease(glfs_fd_t *glfd, glfs_lease_t *lease, glfs_recall_cbk fn,
void *data) __THROW GFAPI_PUBLIC(glfs_lease, 4.0.0);
+/*
+ SYNOPSIS
+
+ glfs_fsetattr: Function to set attributes.
+ glfs_setattr: Function to set attributes
+
+ DESCRIPTION
+
+ The functions are used to set attributes on the file.
+
+ PARAMETERS
+
+ @glfs_fsetattr
+
+ @glfd: The fd of the file for which the attributes are to be set,
+ this fd is returned by glfs_open/glfs_create.
+
+ @glfs_setattr
+
+ @fs: File object.
+
+ @path: The path of the file that is being operated on.
+
+ @follow: Flag used to resolve symlink.
+
+
+ @stat: Struct that has information about the file.
+
+ @valid: This is the mask bit, that accepts GFAPI_SET_ATTR* masks.
+ Refer glfs.h to see the mask definitions.
+
+ Both functions are similar in functionality, just that the
+ func setattr() uses file path whereas the func fsetattr()
+ uses the fd.
+
+ RETURN VALUES
+ 0: Successful completion
+ <0: Failure. @errno will be set with the type of failure
+
+ */
+
+int
+glfs_fsetattr(struct glfs_fd *glfd, struct stat *stat, int valid) __THROW
+ GFAPI_PUBLIC(glfs_fsetattr, future);
+
+int
+glfs_setattr(struct glfs *fs, const char *path, struct stat *stat, int valid,
+ int follow) __THROW GFAPI_PUBLIC(glfs_setattr, future);
+
__END_DECLS
#endif /* !_GLFS_H */