/*
* 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/
#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(struct osd_device *osd, uint64_t dnode, nvlist_t **sa)
{
sa_handle_t *sa_hdl;
goto out_sa;
}
- buf = sa_spill_alloc(KM_SLEEP);
+ buf = osd_zio_buf_alloc(size);
if (buf == NULL) {
rc = -ENOMEM;
goto out_sa;
rc = -sa_lookup(sa_hdl, SA_ZPL_DXATTR(osd), buf, size);
if (rc == 0)
rc = -nvlist_unpack(buf, size, sa, KM_SLEEP);
- sa_spill_free(buf);
+ osd_zio_buf_free(buf, size);
out_sa:
sa_handle_destroy(sa_hdl);
&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 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)
{
if (rc != -ENOENT)
return rc;
- rc = __osd_xattr_get_large(env, osd_obj2dev(obj), 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,
if (rc)
return rc;
- dxattr = sa_spill_alloc(KM_SLEEP);
+ dxattr = osd_zio_buf_alloc(sa_size);
if (dxattr == NULL)
RETURN(-ENOMEM);
rc = osd_object_sa_update(obj, SA_ZPL_DXATTR(osd), dxattr, sa_size, oh);
out_free:
- sa_spill_free(dxattr);
+ osd_zio_buf_free(dxattr, sa_size);
RETURN(rc);
}
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);
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) {
strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0))
continue;
- len = strlen(nvpair_name(nvp));
+ 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, name, 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_object *obj = osd_dt_obj(dt);
struct osd_device *osd = osd_obj2dev(obj);
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)
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, za->za_name, 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;
RETURN(rc);
}
-
-