summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorSoumya Koduri <skoduri@redhat.com>2014-05-21 17:09:49 +0530
committerNiels de Vos <ndevos@redhat.com>2014-05-22 02:33:49 -0700
commit0ba8c6113058ae2ab2a2e38e11a2c95d75056a3b (patch)
treeb92ec8bf0185fcf5c65986b08d303757db40a3e0 /api
parent342689fb936145a310d45d59f06f643e39b944bc (diff)
libgfapi: Added Handle-based ops to get/set/remove extended attributes in the libgfapi.
Cherry picked from commit Change-Id: I1a8e666018d7b93e0bba2d9882935681da909980 and Change-Id: I62f63da37edf722d6d79c75f72ee7403e93e4936 > BUG: 1089414 > Signed-off-by: Soumya Koduri <skoduri@redhat.com> > Reviewed-on: http://review.gluster.org/7308 > Reviewed-by: Vijay Bellur <vbellur@redhat.com> > Tested-by: Vijay Bellur <vbellur@redhat.com> This patch differs a bit from its earlier master patch - * 'DECODE_SYNCOP_ERR' macro is not defined in this code branch. So lines where this macro is used are skipped. * 'syncop_removexattr(..)' definition differs from the one in the master branch. BUG: 1099878 Change-Id: I1e9cce4efeec038b9736065d39887c35752caead Signed-off-by: Soumya Koduri <skoduri@redhat.com> Reviewed-on: http://review.gluster.org/7825 Reviewed-by: Raghavendra G <rgowdapp@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Niels de Vos <ndevos@redhat.com>
Diffstat (limited to 'api')
-rw-r--r--api/src/glfs-handleops.c163
-rw-r--r--api/src/glfs-handles.h13
-rw-r--r--api/src/glfs-internal.h3
3 files changed, 178 insertions, 1 deletions
diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c
index 0f996d3a2da..0538ac6f349 100644
--- a/api/src/glfs-handleops.c
+++ b/api/src/glfs-handleops.c
@@ -217,6 +217,60 @@ out:
}
int
+glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object, const char *name,
+ void *value, size_t size)
+{
+ int ret = 0;
+ xlator_t *subvol = NULL;
+ inode_t *inode = NULL;
+ loc_t loc = {0, };
+ dict_t *xattr = NULL;
+
+ /* validate in args */
+ if ((fs == NULL) || (object == NULL)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ __glfs_entry_fs (fs);
+
+ /* get the active volume */
+ subvol = glfs_active_subvol (fs);
+ if (!subvol) {
+ ret = -1;
+ errno = EIO;
+ goto out;
+ }
+
+ /* get/refresh the in arg objects inode in correlation to the xlator */
+ inode = glfs_resolve_inode (fs, subvol, object);
+ if (!inode) {
+ errno = ESTALE;
+ goto out;
+ }
+
+ /* populate loc */
+ GLFS_LOC_FILL_INODE (inode, loc, out);
+
+ ret = syncop_getxattr (subvol, &loc, &xattr, name);
+
+ if (ret)
+ goto out;
+
+ ret = glfs_getxattr_process (value, size, xattr, name);
+
+out:
+ loc_wipe (&loc);
+
+ if (inode)
+ inode_unref (inode);
+
+ glfs_subvol_done (fs, subvol);
+
+ return ret;
+}
+
+int
glfs_h_setattrs (struct glfs *fs, struct glfs_object *object, struct stat *stat,
int valid)
{
@@ -269,6 +323,115 @@ out:
return ret;
}
+int
+glfs_h_setxattrs (struct glfs *fs, struct glfs_object *object, const char *name,
+ const void *value, size_t size, int flags)
+{
+ int ret = -1;
+ xlator_t *subvol = NULL;
+ inode_t *inode = NULL;
+ loc_t loc = {0, };
+ dict_t *xattr = NULL;
+
+ /* validate in args */
+ if ((fs == NULL) || (object == NULL) ||
+ (name == NULL) || (value == NULL)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ __glfs_entry_fs (fs);
+
+ /* get the active volume */
+ subvol = glfs_active_subvol (fs);
+ if (!subvol) {
+ ret = -1;
+ errno = EIO;
+ goto out;
+ }
+
+ /* get/refresh the in arg objects inode in correlation to the xlator */
+ inode = glfs_resolve_inode (fs, subvol, object);
+ if (!inode) {
+ errno = ESTALE;
+ goto out;
+ }
+
+ xattr = dict_for_key_value (name, value, size);
+ if (!xattr) {
+ ret = -1;
+ errno = ENOMEM;
+ goto out;
+ }
+
+ /* populate loc */
+ GLFS_LOC_FILL_INODE (inode, loc, out);
+
+ /* fop/op */
+ ret = syncop_setxattr (subvol, &loc, xattr, flags);
+
+out:
+ loc_wipe (&loc);
+
+ if (inode)
+ inode_unref (inode);
+
+ if (xattr)
+ dict_unref (xattr);
+
+ glfs_subvol_done (fs, subvol);
+
+ return ret;
+}
+
+int
+glfs_h_removexattrs (struct glfs *fs, struct glfs_object *object, const char *name)
+{
+ int ret = -1;
+ xlator_t *subvol = NULL;
+ inode_t *inode = NULL;
+ loc_t loc = {0, };
+
+ /* validate in args */
+ if ((fs == NULL) || (object == NULL) || (name == NULL)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ __glfs_entry_fs (fs);
+
+ /* get the active volume */
+ subvol = glfs_active_subvol (fs);
+ if (!subvol) {
+ ret = -1;
+ errno = EIO;
+ goto out;
+ }
+
+ /* get/refresh the in arg objects inode in correlation to the xlator */
+ inode = glfs_resolve_inode (fs, subvol, object);
+ if (!inode) {
+ errno = ESTALE;
+ goto out;
+ }
+
+ /* populate loc */
+ GLFS_LOC_FILL_INODE (inode, loc, out);
+
+ /* fop/op */
+ ret = syncop_removexattr (subvol, &loc, name);
+
+out:
+ loc_wipe (&loc);
+
+ if (inode)
+ inode_unref (inode);
+
+ glfs_subvol_done (fs, subvol);
+
+ return ret;
+}
+
struct glfs_fd *
glfs_h_open (struct glfs *fs, struct glfs_object *object, int flags)
{
diff --git a/api/src/glfs-handles.h b/api/src/glfs-handles.h
index 437f2cbc8a5..d095d9e622f 100644
--- a/api/src/glfs-handles.h
+++ b/api/src/glfs-handles.h
@@ -111,9 +111,17 @@ int glfs_h_stat(struct glfs *fs, struct glfs_object *object, struct stat *stat);
int glfs_h_getattrs (struct glfs *fs, struct glfs_object *object,
struct stat *stat);
+int glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object,
+ const char *name, void *value,
+ size_t size) __THROW;
+
int glfs_h_setattrs (struct glfs *fs, struct glfs_object *object,
struct stat *sb, int valid);
+int glfs_h_setxattrs (struct glfs *fs, struct glfs_object *object,
+ const char *name, const void *value,
+ size_t size, int flags) __THROW;
+
int glfs_h_readlink (struct glfs *fs, struct glfs_object *object, char *buf,
size_t bufsiz);
@@ -124,6 +132,9 @@ int glfs_h_rename (struct glfs *fs, struct glfs_object *olddir,
const char *oldname, struct glfs_object *newdir,
const char *newname);
+int glfs_h_removexattrs (struct glfs *fs, struct glfs_object *object,
+ const char *name) __THROW;
+
/* Operations enabling opaque invariant handle to object transitions */
ssize_t glfs_h_extract_handle (struct glfs_object *object,
unsigned char *handle, int len);
@@ -140,4 +151,4 @@ struct glfs_fd *glfs_h_open (struct glfs *fs, struct glfs_object *object,
__END_DECLS
-#endif /* !_GLFS_HANDLES_H */ \ No newline at end of file
+#endif /* !_GLFS_HANDLES_H */
diff --git a/api/src/glfs-internal.h b/api/src/glfs-internal.h
index 6ed4aeae16f..976c958a0f5 100644
--- a/api/src/glfs-internal.h
+++ b/api/src/glfs-internal.h
@@ -197,6 +197,9 @@ int glfs_loc_touchup (loc_t *loc);
void glfs_iatt_to_stat (struct glfs *fs, struct iatt *iatt, struct stat *stat);
int glfs_loc_link (loc_t *loc, struct iatt *iatt);
int glfs_loc_unlink (loc_t *loc);
+dict_t * dict_for_key_value (const char *name, const char *value, size_t size);
+int glfs_getxattr_process (void *value, size_t size, dict_t *xattr,
+ const char *name);
/* Sends RPC call to glusterd to fetch required volume info */
int glfs_get_volume_info (struct glfs *fs);