gfapi: add glfs_h_acl_set() and glfs_h_acl_get()

These two functions add support for POSIX ACLs through the GFAPI-handle
interface.

The initial infrastructure for POSIX ACLs based on libacl has been added
with the required changes to the POSIX xlator:
- http://review.gluster.org/9627

NetBSD does not support POSIX ACLs, so using any of the functions should
return ENOTSUP.

URL: http://www.gluster.org/community/documentation/index.php/Features/Improved_POSIX_ACLs
Change-Id: Ie74f3f963c3f9d576cb2f2a1e6d97e3cd4b01eda
BUG: 1185654
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: http://review.gluster.org/9736
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
This commit is contained in:
Niels de Vos 2015-02-24 19:42:49 +01:00 committed by Vijay Bellur
parent 87c7fa3cfd
commit 728fcd41eb
9 changed files with 143 additions and 16 deletions

@ -18,7 +18,7 @@ libgfapi_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \
-I$(top_srcdir)/rpc/xdr/src
libgfapi_la_LDFLAGS = -version-info $(GFAPI_LT_VERSION) \
$(GFAPI_EXTRA_LDFLAGS)
$(GFAPI_EXTRA_LDFLAGS) $(ACL_LIBS)
xlator_LTLIBRARIES = api.la
xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/mount

@ -127,6 +127,8 @@ _pub_glfs_h_access _glfs_h_access$GFAPI_3.6.0
_pub_glfs_ipc _glfs_ipc$GFAPI_3.7.0
_pub_glfs_h_poll_upcall _glfs_h_poll_upcall$GFAPI_3.7.0
_pub_glfs_h_acl_set _glfs_h_acl_set$GFAPI_3.7.0
_pub_glfs_h_acl_get _glfs_h_acl_get$GFAPI_3.7.0
_priv_glfs_free_from_ctx _glfs_free_from_ctx$GFAPI_PRIVATE_3.7.0
_priv_glfs_new_from_ctx _glfs_new_from_ctx$GFAPI_PRIVATE_3.7.0

@ -149,6 +149,8 @@ GFAPI_3.7.0 {
global:
glfs_ipc;
glfs_h_poll_upcall;
glfs_h_acl_set;
glfs_h_acl_get;
} GFAPI_3.6.0;
GFAPI_PRIVATE_3.7.0 {

@ -231,14 +231,13 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_getattrs, 3.4.2);
int
pub_glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object,
const char *name, void *value, size_t size)
glfs_h_getxattrs_common (struct glfs *fs, struct glfs_object *object,
dict_t **xattr, const char *name)
{
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)) {
@ -266,9 +265,35 @@ pub_glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object,
/* populate loc */
GLFS_LOC_FILL_INODE (inode, loc, out);
ret = syncop_getxattr (subvol, &loc, &xattr, name, NULL);
ret = syncop_getxattr (subvol, &loc, xattr, name, NULL);
DECODE_SYNCOP_ERR (ret);
out:
loc_wipe (&loc);
if (inode)
inode_unref (inode);
glfs_subvol_done (fs, subvol);
return ret;
}
int
pub_glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object,
const char *name, void *value, size_t size)
{
int ret = 0;
dict_t *xattr = NULL;
/* validate in args */
if ((fs == NULL) || (object == NULL)) {
errno = EINVAL;
return -1;
}
ret = glfs_h_getxattrs_common (fs, object, &xattr, name);
if (ret)
goto out;
@ -279,13 +304,8 @@ pub_glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object,
ret = glfs_listxattr_process (value, size, xattr);
out:
loc_wipe (&loc);
if (inode)
inode_unref (inode);
glfs_subvol_done (fs, subvol);
if (xattr)
dict_unref (xattr);
return ret;
}
@ -1723,3 +1743,89 @@ err:
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_poll_upcall, 3.7.0);
#ifdef HAVE_ACL_LIBACL_H
#include "glusterfs-acl.h"
#include <acl/libacl.h>
int
pub_glfs_h_acl_set (struct glfs *fs, struct glfs_object *object,
const acl_type_t type, const acl_t acl)
{
int ret = -1;
char *acl_s = NULL;
const char *acl_key = NULL;
ssize_t acl_len = 0;
if (!fs || !object || !acl) {
errno = EINVAL;
return ret;
}
acl_key = gf_posix_acl_get_key (type);
if (!acl_key)
return ret;
acl_s = acl_to_any_text (acl, NULL, ',',
TEXT_ABBREVIATE | TEXT_NUMERIC_IDS);
if (!acl_s)
return ret;
ret = pub_glfs_h_setxattrs (fs, object, acl_key, acl_s, acl_len, 0);
acl_free (acl_s);
return ret;
}
acl_t
pub_glfs_h_acl_get (struct glfs *fs, struct glfs_object *object,
const acl_type_t type)
{
int ret = 0;
acl_t acl = NULL;
char *acl_s = NULL;
dict_t *xattr = NULL;
const char *acl_key = NULL;
if (!fs || !object) {
errno = EINVAL;
return NULL;
}
acl_key = gf_posix_acl_get_key (type);
if (!acl_key)
return NULL;
ret = glfs_h_getxattrs_common (fs, object, &xattr, acl_key);
if (ret)
return NULL;
ret = dict_get_str (xattr, (char *)acl_key, &acl_s);
if (ret == -1)
goto out;
acl = acl_from_text (acl_s);
out:
GF_FREE (acl_s);
return acl;
}
#else /* !HAVE_ACL_LIBACL_H */
acl_t
pub_glfs_h_acl_get (struct glfs *fs, struct glfs_object *object,
const acl_type_t type)
{
errno = ENOTSUP;
return NULL;
}
int
pub_glfs_h_acl_set (struct glfs *fs, struct glfs_object *object,
const acl_type_t type, const acl_t acl)
{
errno = ENOTSUP;
return -1;
}
#endif
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_acl_set, 3.7.0);
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_acl_get, 3.7.0);

@ -271,6 +271,16 @@ int
glfs_h_poll_upcall (struct glfs *fs, struct callback_arg *cbk) __THROW
GFAPI_PUBLIC(glfs_h_poll_upcall, 3.7.0);
int
glfs_h_acl_set (struct glfs *fs, struct glfs_object *object,
const acl_type_t type, const acl_t acl) __THROW;
GFAPI_PUBLIC(glfs_h_acl_set, 3.7.0);
acl_t
glfs_h_acl_get (struct glfs *fs, struct glfs_object *object,
const acl_type_t type) __THROW;
GFAPI_PUBLIC(glfs_h_acl_get, 3.7.0);
__END_DECLS
#endif /* !_GLFS_HANDLES_H */

@ -26,7 +26,7 @@ enum glfs_mem_types_ {
glfs_mt_glfs_object_t,
glfs_mt_readdirbuf_t,
glfs_mt_upcall_entry_t,
glfs_mt_acl_t,
glfs_mt_end
};
#endif

@ -42,6 +42,13 @@
#include <dirent.h>
#include <sys/statvfs.h>
#if defined(HAVE_SYS_ACL_H) || (defined(USE_POSIX_ACLS) && USE_POSIX_ACLS)
#include <sys/acl.h>
#else
typedef void *acl_t;
typedef int acl_type_t;
#endif
/* Portability non glibc c++ build systems */
#ifndef __THROW
# if defined __cplusplus

@ -7,5 +7,5 @@ Name: glusterfs-api
Description: GlusterFS API
/* This is the API version, NOT package version */
Version: @GFAPI_VERSION@
Libs: -L${libdir} -lgfapi -lglusterfs -lgfrpc -lgfxdr
Cflags: -I${includedir}/glusterfs -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64
Libs: -L${libdir} @GFAPI_LIBS@ -lgfapi -lglusterfs -lgfrpc -lgfxdr
Cflags: -I${includedir}/glusterfs -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -DUSE_POSIX_ACLS=@USE_POSIX_ACLS@

@ -6,7 +6,7 @@ glfsheal_LDADD = $(top_builddir)/libglusterfs/src/libglusterfs.la $(GF_LDADD)\
$(RLLIBS) $(top_builddir)/rpc/xdr/src/libgfxdr.la \
$(top_builddir)/rpc/rpc-lib/src/libgfrpc.la \
$(top_builddir)/api/src/libgfapi.la \
$(GF_GLUSTERFS_LIBS) $(XML_LIBS)
$(GF_GLUSTERFS_LIBS) $(XML_LIBS) $(GFAPI_LIBS)
glfsheal_LDFLAGS = $(GF_LDFLAGS)