/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
- */
-/*
- * Copyright (c) 2012, 2013, Intel Corporation.
- * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2014, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
* Author: Mike Pershin <tappro@whamcloud.com>
*/
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
#define DEBUG_SUBSYSTEM S_OSD
#include <lustre_ver.h>
#include <sys/sa_impl.h>
#include <sys/txg.h>
+#include <linux/posix_acl_xattr.h>
-/*
- * Copy an extended attribute into the buffer provided, or compute the
- * required buffer size.
- *
- * If buf is NULL, it computes the required buffer size.
- *
- * Returns 0 on success or a negative error number on failure.
- * On success, the number of bytes used / required is stored in 'size'.
- *
- * No locking is done here.
- */
-int __osd_xattr_load(udmu_objset_t *uos, uint64_t dnode, nvlist_t **sa_xattr)
+
+int __osd_xattr_load(struct osd_device *osd, uint64_t dnode, nvlist_t **sa)
{
sa_handle_t *sa_hdl;
char *buf;
if (unlikely(dnode == ZFS_NO_OBJECT))
return -ENOENT;
- rc = -sa_handle_get(uos->os, dnode, NULL, SA_HDL_PRIVATE, &sa_hdl);
+ rc = -sa_handle_get(osd->od_os, dnode, NULL, SA_HDL_PRIVATE, &sa_hdl);
if (rc)
return rc;
- rc = -sa_size(sa_hdl, SA_ZPL_DXATTR(uos), &size);
+ rc = -sa_size(sa_hdl, SA_ZPL_DXATTR(osd), &size);
if (rc) {
if (rc == -ENOENT)
- rc = -nvlist_alloc(sa_xattr, NV_UNIQUE_NAME, KM_SLEEP);
+ rc = -nvlist_alloc(sa, NV_UNIQUE_NAME, KM_SLEEP);
goto out_sa;
}
rc = -ENOMEM;
goto out_sa;
}
- rc = -sa_lookup(sa_hdl, SA_ZPL_DXATTR(uos), buf, size);
+ rc = -sa_lookup(sa_hdl, SA_ZPL_DXATTR(osd), buf, size);
if (rc == 0)
- rc = -nvlist_unpack(buf, size, sa_xattr, KM_SLEEP);
+ rc = -nvlist_unpack(buf, size, sa, KM_SLEEP);
sa_spill_free(buf);
out_sa:
sa_handle_destroy(sa_hdl);
LASSERT(obj->oo_sa_xattr == NULL);
LASSERT(obj->oo_db != NULL);
- return __osd_xattr_load(&osd_obj2dev(obj)->od_objset,
- obj->oo_db->db_object, &obj->oo_sa_xattr);
+ return __osd_xattr_load(osd_obj2dev(obj), obj->oo_db->db_object,
+ &obj->oo_sa_xattr);
}
-int __osd_sa_xattr_get(const struct lu_env *env, struct osd_object *obj,
- const struct lu_buf *buf, const char *name, int *sizep)
+static int
+__osd_sa_xattr_get(const struct lu_env *env, struct osd_object *obj,
+ const struct lu_buf *buf, const char *name, int *sizep)
{
uchar_t *nv_value;
int rc;
return 0;
}
-int __osd_xattr_get_large(const struct lu_env *env, udmu_objset_t *uos,
+int __osd_xattr_get_large(const struct lu_env *env, struct osd_device *osd,
uint64_t xattr, struct lu_buf *buf,
const char *name, int *sizep)
{
return -ENOENT;
/* Lookup the object number containing the xattr data */
- rc = -zap_lookup(uos->os, xattr, name, sizeof(uint64_t), 1,
+ rc = -zap_lookup(osd->od_os, xattr, name, sizeof(uint64_t), 1,
&xa_data_obj);
if (rc)
return rc;
- rc = __osd_obj2dbuf(env, uos->os, xa_data_obj, &xa_data_db, FTAG);
+ rc = __osd_obj2dbuf(env, osd->od_os, xa_data_obj, &xa_data_db);
if (rc)
return rc;
- rc = -sa_handle_get(uos->os, xa_data_obj, NULL, SA_HDL_PRIVATE,
+ rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL, SA_HDL_PRIVATE,
&sa_hdl);
if (rc)
goto out_rele;
/* Get the xattr value length / object size */
- rc = -sa_lookup(sa_hdl, SA_ZPL_SIZE(uos), &size, 8);
+ rc = -sa_lookup(sa_hdl, SA_ZPL_SIZE(osd), &size, 8);
if (rc)
goto out;
goto out;
}
- rc = -dmu_read(uos->os, xa_data_db->db_object, 0,
+ rc = -dmu_read(osd->od_os, xa_data_db->db_object, 0,
size, buf->lb_buf, DMU_READ_PREFETCH);
out:
return rc;
}
+/**
+ * Copy an extended attribute into the buffer provided, or compute
+ * the required buffer size if \a buf is NULL.
+ *
+ * On success, the number of bytes used or required is stored in \a sizep.
+ *
+ * Note that no locking is done here.
+ *
+ * \param[in] env execution environment
+ * \param[in] obj object for which to retrieve xattr
+ * \param[out] buf buffer to store xattr value in
+ * \param[in] name name of xattr to copy
+ * \param[out] sizep bytes used or required to store xattr
+ *
+ * \retval 0 on success
+ * \retval negative negated errno on failure
+ */
int __osd_xattr_get(const struct lu_env *env, struct osd_object *obj,
- struct lu_buf *buf, const char *name, int *sizep)
+ struct lu_buf *buf, const char *name, int *sizep)
{
int rc;
if (rc != -ENOENT)
return rc;
- rc = __osd_xattr_get_large(env, &osd_obj2dev(obj)->od_objset,
- obj->oo_xattr, buf, name, sizep);
-
- return rc;
+ return __osd_xattr_get_large(env, osd_obj2dev(obj), obj->oo_xattr,
+ buf, name, sizep);
}
int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
- struct lu_buf *buf, const char *name,
- struct lustre_capa *capa)
+ struct lu_buf *buf, const char *name,
+ struct lustre_capa *capa)
{
struct osd_object *obj = osd_dt_obj(dt);
int rc, size = 0;
LASSERT(osd_invariant(obj));
LASSERT(dt_object_exists(dt));
+ if (!osd_obj2dev(obj)->od_posix_acl &&
+ (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0 ||
+ strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0))
+ RETURN(-EOPNOTSUPP);
+
down(&obj->oo_guard);
rc = __osd_xattr_get(env, obj, buf, name, &size);
up(&obj->oo_guard);
}
void __osd_xattr_declare_set(const struct lu_env *env, struct osd_object *obj,
- int vallen, const char *name, struct osd_thandle *oh)
+ int vallen, const char *name,
+ struct osd_thandle *oh)
{
struct osd_device *osd = osd_obj2dev(obj);
- udmu_objset_t *uos = &osd->od_objset;
dmu_buf_t *db = obj->oo_db;
dmu_tx_t *tx = oh->ot_tx;
uint64_t xa_data_obj;
return;
}
- rc = -zap_lookup(uos->os, obj->oo_xattr, name, sizeof(uint64_t), 1,
+ rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
&xa_data_obj);
if (rc == 0) {
/*
}
int osd_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
- const struct lu_buf *buf, const char *name,
- int fl, struct thandle *handle)
+ const struct lu_buf *buf, const char *name,
+ int fl, struct thandle *handle)
{
struct osd_object *obj = osd_dt_obj(dt);
struct osd_thandle *oh;
*/
static int
__osd_sa_xattr_update(const struct lu_env *env, struct osd_object *obj,
- struct osd_thandle *oh)
+ struct osd_thandle *oh)
{
struct osd_device *osd = osd_obj2dev(obj);
- udmu_objset_t *uos = &osd->od_objset;
char *dxattr;
size_t sa_size;
int rc;
if (rc)
GOTO(out_free, rc);
- rc = osd_object_sa_update(obj, SA_ZPL_DXATTR(uos), dxattr, sa_size, oh);
+ rc = osd_object_sa_update(obj, SA_ZPL_DXATTR(osd), dxattr, sa_size, oh);
out_free:
sa_spill_free(dxattr);
RETURN(rc);
}
int __osd_sa_xattr_set(const struct lu_env *env, struct osd_object *obj,
- const struct lu_buf *buf, const char *name, int fl,
- struct osd_thandle *oh)
+ const struct lu_buf *buf, const char *name, int fl,
+ struct osd_thandle *oh)
{
uchar_t *nv_value;
size_t size;
return rc;
}
+ /* Ensure xattr doesn't exist in ZAP */
+ if (obj->oo_xattr != ZFS_NO_OBJECT) {
+ struct osd_device *osd = osd_obj2dev(obj);
+ uint64_t objid;
+ rc = -zap_lookup(osd->od_os, obj->oo_xattr,
+ name, 8, 1, &objid);
+ if (rc == 0) {
+ rc = -dmu_object_free(osd->od_os, objid, oh->ot_tx);
+ if (rc == 0)
+ zap_remove(osd->od_os, obj->oo_xattr,
+ name, oh->ot_tx);
+ }
+ }
+
rc = -nvlist_add_byte_array(obj->oo_sa_xattr, name,
(uchar_t *)buf->lb_buf, buf->lb_len);
if (rc)
struct osd_thandle *oh)
{
struct osd_device *osd = osd_obj2dev(obj);
- udmu_objset_t *uos = &osd->od_objset;
dmu_buf_t *xa_zap_db = NULL;
dmu_buf_t *xa_data_db = NULL;
uint64_t xa_data_obj;
la->la_valid = LA_MODE;
la->la_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO;
- rc = __osd_zap_create(env, uos, &xa_zap_db, tx, la,
- obj->oo_db->db_object, FTAG, 0);
+ rc = __osd_zap_create(env, osd, &xa_zap_db, tx, la,
+ obj->oo_db->db_object, 0);
if (rc)
return rc;
obj->oo_xattr = xa_zap_db->db_object;
- rc = osd_object_sa_update(obj, SA_ZPL_XATTR(uos),
+ rc = osd_object_sa_update(obj, SA_ZPL_XATTR(osd),
&obj->oo_xattr, 8, oh);
if (rc)
goto out;
}
- rc = -zap_lookup(uos->os, obj->oo_xattr, name, sizeof(uint64_t), 1,
- &xa_data_obj);
+ rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
+ &xa_data_obj);
if (rc == 0) {
if (fl & LU_XATTR_CREATE) {
rc = -EEXIST;
* Entry already exists.
* We'll truncate the existing object.
*/
- rc = __osd_obj2dbuf(env, uos->os, xa_data_obj,
- &xa_data_db, FTAG);
+ rc = __osd_obj2dbuf(env, osd->od_os, xa_data_obj,
+ &xa_data_db);
if (rc)
goto out;
- rc = -sa_handle_get(uos->os, xa_data_obj, NULL,
+ rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL,
SA_HDL_PRIVATE, &sa_hdl);
if (rc)
goto out;
- rc = -sa_lookup(sa_hdl, SA_ZPL_SIZE(uos), &size, 8);
+ rc = -sa_lookup(sa_hdl, SA_ZPL_SIZE(osd), &size, 8);
if (rc)
goto out_sa;
- rc = -dmu_free_range(uos->os, xa_data_db->db_object,
+ rc = -dmu_free_range(osd->od_os, xa_data_db->db_object,
0, DMU_OBJECT_END, tx);
if (rc)
goto out_sa;
la->la_valid = LA_MODE;
la->la_mode = S_IFREG | S_IRUGO | S_IWUSR;
- rc = __osd_object_create(env, uos, &xa_data_db, tx, la,
- obj->oo_xattr, FTAG);
+ rc = __osd_object_create(env, osd, &xa_data_db, tx, la,
+ obj->oo_xattr);
if (rc)
goto out;
xa_data_obj = xa_data_db->db_object;
- rc = -sa_handle_get(uos->os, xa_data_obj, NULL,
+ rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL,
SA_HDL_PRIVATE, &sa_hdl);
if (rc)
goto out;
- rc = -zap_add(uos->os, obj->oo_xattr, name, sizeof(uint64_t),
+ rc = -zap_add(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t),
1, &xa_data_obj, tx);
if (rc)
goto out_sa;
}
/* Finally write the xattr value */
- dmu_write(uos->os, xa_data_obj, 0, buf->lb_len, buf->lb_buf, tx);
+ dmu_write(osd->od_os, xa_data_obj, 0, buf->lb_len, buf->lb_buf, tx);
size = buf->lb_len;
- rc = -sa_update(sa_hdl, SA_ZPL_SIZE(uos), &size, 8, tx);
+ rc = -sa_update(sa_hdl, SA_ZPL_SIZE(osd), &size, 8, tx);
out_sa:
sa_handle_destroy(sa_hdl);
LASSERT(dt_object_exists(dt));
LASSERT(obj->oo_db);
+ if (!osd_obj2dev(obj)->od_posix_acl &&
+ (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0 ||
+ strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0))
+ RETURN(-EOPNOTSUPP);
+
+ if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_OVERFLOW) &&
+ strcmp(name, XATTR_NAME_LINK) == 0)
+ RETURN(-ENOSPC);
+
oh = container_of0(handle, struct osd_thandle, ot_super);
down(&obj->oo_guard);
const char *name, struct osd_thandle *oh)
{
struct osd_device *osd = osd_obj2dev(obj);
- udmu_objset_t *uos = &osd->od_objset;
dmu_tx_t *tx = oh->ot_tx;
uint64_t xa_data_obj;
int rc;
if (obj->oo_xattr == ZFS_NO_OBJECT)
return;
- rc = -zap_lookup(uos->os, obj->oo_xattr, name, 8, 1, &xa_data_obj);
+ rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, 8, 1, &xa_data_obj);
if (rc == 0) {
/*
* Entry exists.
}
int osd_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
- const char *name, struct thandle *handle)
+ const char *name, struct thandle *handle)
{
struct osd_object *obj = osd_dt_obj(dt);
struct osd_thandle *oh;
}
int __osd_sa_xattr_del(const struct lu_env *env, struct osd_object *obj,
- const char *name, struct osd_thandle *oh)
+ const char *name, struct osd_thandle *oh)
{
int rc;
}
int __osd_xattr_del(const struct lu_env *env, struct osd_object *obj,
- const char *name, struct osd_thandle *oh)
+ const char *name, struct osd_thandle *oh)
{
struct osd_device *osd = osd_obj2dev(obj);
- udmu_objset_t *uos = &osd->od_objset;
uint64_t xa_data_obj;
int rc;
if (obj->oo_xattr == ZFS_NO_OBJECT)
return 0;
- rc = -zap_lookup(uos->os, obj->oo_xattr, name, sizeof(uint64_t), 1,
+ rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
&xa_data_obj);
if (rc == -ENOENT) {
rc = 0;
* Entry exists.
* We'll delete the existing object and ZAP entry.
*/
- rc = __osd_object_free(uos, xa_data_obj, oh->ot_tx);
+ rc = -dmu_object_free(osd->od_os, xa_data_obj, oh->ot_tx);
if (rc)
return rc;
- rc = -zap_remove(uos->os, obj->oo_xattr, name, oh->ot_tx);
+ rc = -zap_remove(osd->od_os, obj->oo_xattr, name, oh->ot_tx);
}
return rc;
}
int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
- const char *name, struct thandle *handle,
- struct lustre_capa *capa)
+ const char *name, struct thandle *handle,
+ struct lustre_capa *capa)
{
struct osd_object *obj = osd_dt_obj(dt);
struct osd_thandle *oh;
oh = container_of0(handle, struct osd_thandle, ot_super);
LASSERT(oh->ot_tx != NULL);
+ if (!osd_obj2dev(obj)->od_posix_acl &&
+ (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0 ||
+ strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0))
+ RETURN(-EOPNOTSUPP);
+
down(&obj->oo_guard);
rc = __osd_xattr_del(env, obj, name, oh);
up(&obj->oo_guard);
static int
osd_sa_xattr_list(const struct lu_env *env, struct osd_object *obj,
- struct lu_buf *lb)
+ const struct lu_buf *lb)
{
nvpair_t *nvp = NULL;
- int len, counted = 0, remain = lb->lb_len;
+ int len, counted = 0;
int rc = 0;
if (obj->oo_sa_xattr == NULL) {
LASSERT(obj->oo_sa_xattr);
while ((nvp = nvlist_next_nvpair(obj->oo_sa_xattr, nvp)) != NULL) {
- len = strlen(nvpair_name(nvp));
+ const char *name = nvpair_name(nvp);
+
+ if (!osd_obj2dev(obj)->od_posix_acl &&
+ (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0 ||
+ strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0))
+ continue;
+
+ len = strlen(name);
if (lb->lb_buf != NULL) {
- if (len + 1 > remain)
+ if (counted + len + 1 > lb->lb_len)
return -ERANGE;
- memcpy(lb->lb_buf, nvpair_name(nvp), len);
- lb->lb_buf += len;
- *((char *)lb->lb_buf) = '\0';
- lb->lb_buf++;
- remain -= len + 1;
+ memcpy(lb->lb_buf + counted, name, len + 1);
}
counted += len + 1;
}
}
int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
- struct lu_buf *lb, struct lustre_capa *capa)
+ const struct lu_buf *lb, struct lustre_capa *capa)
{
- struct osd_thread_info *oti = osd_oti_get(env);
struct osd_object *obj = osd_dt_obj(dt);
struct osd_device *osd = osd_obj2dev(obj);
- udmu_objset_t *uos = &osd->od_objset;
+ zap_attribute_t *za = &osd_oti_get(env)->oti_za;
zap_cursor_t *zc;
- int rc, counted = 0, remain = lb->lb_len;
+ int rc, counted;
ENTRY;
LASSERT(obj->oo_db != NULL);
rc = osd_sa_xattr_list(env, obj, lb);
if (rc < 0)
GOTO(out, rc);
+
counted = rc;
- remain -= counted;
/* continue with dnode xattr if any */
if (obj->oo_xattr == ZFS_NO_OBJECT)
GOTO(out, rc = counted);
- rc = -udmu_zap_cursor_init(&zc, uos, obj->oo_xattr, 0);
+ rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0);
if (rc)
GOTO(out, rc);
- while ((rc = -udmu_zap_cursor_retrieve_key(env, zc, oti->oti_key,
- MAXNAMELEN)) == 0) {
- rc = strlen(oti->oti_key);
+ while ((rc = -zap_cursor_retrieve(zc, za)) == 0) {
+ if (!osd_obj2dev(obj)->od_posix_acl &&
+ (strcmp(za->za_name, POSIX_ACL_XATTR_ACCESS) == 0 ||
+ strcmp(za->za_name, POSIX_ACL_XATTR_DEFAULT) == 0)) {
+ zap_cursor_advance(zc);
+ continue;
+ }
+
+ rc = strlen(za->za_name);
if (lb->lb_buf != NULL) {
- if (rc + 1 > remain)
+ if (counted + rc + 1 > lb->lb_len)
RETURN(-ERANGE);
- memcpy(lb->lb_buf, oti->oti_key, rc);
- lb->lb_buf += rc;
- *((char *)lb->lb_buf) = '\0';
- lb->lb_buf++;
- remain -= rc + 1;
+ memcpy(lb->lb_buf + counted, za->za_name, rc + 1);
}
counted += rc + 1;
rc = counted;
out_fini:
- udmu_zap_cursor_fini(zc);
+ osd_zap_cursor_fini(zc);
out:
up(&obj->oo_guard);
RETURN(rc);
}
-
-