4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osd-zfs/osd_xattr.c
37 * functions to manipulate extended attributes and system attributes
39 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
40 * Author: Mike Pershin <tappro@whamcloud.com>
43 #define DEBUG_SUBSYSTEM S_OSD
45 #include <lustre_ver.h>
46 #include <libcfs/libcfs.h>
47 #include <obd_support.h>
48 #include <lustre_net.h>
50 #include <obd_class.h>
51 #include <lustre_disk.h>
52 #include <lustre_fid.h>
54 #include "osd_internal.h"
56 #include <sys/dnode.h>
61 #include <sys/spa_impl.h>
62 #include <sys/zfs_znode.h>
63 #include <sys/dmu_tx.h>
64 #include <sys/dmu_objset.h>
65 #include <sys/dsl_prop.h>
66 #include <sys/sa_impl.h>
69 #include <linux/posix_acl_xattr.h>
72 int __osd_xattr_load(struct osd_device *osd, uint64_t dnode, nvlist_t **sa)
78 if (unlikely(dnode == ZFS_NO_OBJECT))
81 rc = -sa_handle_get(osd->od_os, dnode, NULL, SA_HDL_PRIVATE, &sa_hdl);
85 rc = -sa_size(sa_hdl, SA_ZPL_DXATTR(osd), &size);
88 rc = -nvlist_alloc(sa, NV_UNIQUE_NAME, KM_SLEEP);
92 buf = osd_zio_buf_alloc(size);
97 rc = -sa_lookup(sa_hdl, SA_ZPL_DXATTR(osd), buf, size);
99 rc = -nvlist_unpack(buf, size, sa, KM_SLEEP);
100 osd_zio_buf_free(buf, size);
102 sa_handle_destroy(sa_hdl);
107 static inline int __osd_xattr_cache(const struct lu_env *env,
108 struct osd_object *obj)
110 LASSERT(obj->oo_sa_xattr == NULL);
111 LASSERT(obj->oo_db != NULL);
113 return __osd_xattr_load(osd_obj2dev(obj), obj->oo_db->db_object,
118 __osd_sa_xattr_get(const struct lu_env *env, struct osd_object *obj,
119 const struct lu_buf *buf, const char *name, int *sizep)
124 LASSERT(obj->oo_sa_hdl);
126 if (obj->oo_sa_xattr == NULL) {
127 rc = __osd_xattr_cache(env, obj);
132 LASSERT(obj->oo_sa_xattr);
133 rc = -nvlist_lookup_byte_array(obj->oo_sa_xattr, name, &nv_value,
138 if (buf == NULL || buf->lb_buf == NULL) {
139 /* return the required size by *sizep */
143 if (*sizep > buf->lb_len)
144 return -ERANGE; /* match ldiskfs error */
146 memcpy(buf->lb_buf, nv_value, *sizep);
150 int __osd_xattr_get_large(const struct lu_env *env, struct osd_device *osd,
151 uint64_t xattr, struct lu_buf *buf,
152 const char *name, int *sizep)
154 dmu_buf_t *xa_data_db;
155 sa_handle_t *sa_hdl = NULL;
156 uint64_t xa_data_obj, size;
159 /* are there any extended attributes? */
160 if (xattr == ZFS_NO_OBJECT)
163 /* Lookup the object number containing the xattr data */
164 rc = -zap_lookup(osd->od_os, xattr, name, sizeof(uint64_t), 1,
169 rc = __osd_obj2dbuf(env, osd->od_os, xa_data_obj, &xa_data_db);
173 rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL, SA_HDL_PRIVATE,
178 /* Get the xattr value length / object size */
179 rc = -sa_lookup(sa_hdl, SA_ZPL_SIZE(osd), &size, 8);
183 if (size > INT_MAX) {
190 if (buf == NULL || buf->lb_buf == NULL) {
191 /* We only need to return the required size */
194 if (*sizep > buf->lb_len) {
195 rc = -ERANGE; /* match ldiskfs error */
199 rc = -dmu_read(osd->od_os, xa_data_db->db_object, 0,
200 size, buf->lb_buf, DMU_READ_PREFETCH);
203 sa_handle_destroy(sa_hdl);
205 dmu_buf_rele(xa_data_db, FTAG);
211 * Copy an extended attribute into the buffer provided, or compute
212 * the required buffer size if \a buf is NULL.
214 * On success, the number of bytes used or required is stored in \a sizep.
216 * Note that no locking is done here.
218 * \param[in] env execution environment
219 * \param[in] obj object for which to retrieve xattr
220 * \param[out] buf buffer to store xattr value in
221 * \param[in] name name of xattr to copy
222 * \param[out] sizep bytes used or required to store xattr
224 * \retval 0 on success
225 * \retval negative negated errno on failure
227 int __osd_xattr_get(const struct lu_env *env, struct osd_object *obj,
228 struct lu_buf *buf, const char *name, int *sizep)
232 if (unlikely(!dt_object_exists(&obj->oo_dt) || obj->oo_destroyed))
235 /* check SA_ZPL_DXATTR first then fallback to directory xattr */
236 rc = __osd_sa_xattr_get(env, obj, buf, name, sizep);
240 return __osd_xattr_get_large(env, osd_obj2dev(obj), obj->oo_xattr,
244 int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
245 struct lu_buf *buf, const char *name)
247 struct osd_object *obj = osd_dt_obj(dt);
251 LASSERT(obj->oo_db != NULL);
252 LASSERT(osd_invariant(obj));
254 if (!osd_obj2dev(obj)->od_posix_acl &&
255 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
256 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
259 down_read(&obj->oo_guard);
260 rc = __osd_xattr_get(env, obj, buf, name, &size);
261 up_read(&obj->oo_guard);
270 /* the function is used to declare EAs when SA is not supported */
271 void __osd_xattr_declare_legacy(const struct lu_env *env,
272 struct osd_object *obj,
273 int vallen, const char *name,
274 struct osd_thandle *oh)
276 struct osd_device *osd = osd_obj2dev(obj);
277 dmu_tx_t *tx = oh->ot_tx;
278 uint64_t xa_data_obj;
281 if (obj->oo_xattr == ZFS_NO_OBJECT) {
282 /* xattr zap + entry */
283 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, (char *) name);
284 /* xattr value obj */
285 dmu_tx_hold_sa_create(tx, ZFS_SA_BASE_ATTR_SIZE);
286 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, vallen);
290 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
294 * Entry already exists.
295 * We'll truncate the existing object.
297 dmu_tx_hold_bonus(tx, xa_data_obj);
298 dmu_tx_hold_free(tx, xa_data_obj, vallen, DMU_OBJECT_END);
299 dmu_tx_hold_write(tx, xa_data_obj, 0, vallen);
300 } else if (rc == -ENOENT) {
302 * Entry doesn't exist, we need to create a new one and a new
303 * object to store the value.
305 dmu_tx_hold_bonus(tx, obj->oo_xattr);
306 dmu_tx_hold_zap(tx, obj->oo_xattr, TRUE, (char *) name);
307 dmu_tx_hold_sa_create(tx, ZFS_SA_BASE_ATTR_SIZE);
308 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, vallen);
312 void __osd_xattr_declare_set(const struct lu_env *env, struct osd_object *obj,
313 int vallen, const char *name,
314 struct osd_thandle *oh)
316 dmu_buf_t *db = obj->oo_db;
317 dmu_tx_t *tx = oh->ot_tx;
319 if (unlikely(obj->oo_destroyed))
322 if (unlikely(!osd_obj2dev(obj)->od_xattr_in_sa)) {
323 __osd_xattr_declare_legacy(env, obj, vallen, name, oh);
327 /* declare EA in SA */
328 if (dt_object_exists(&obj->oo_dt)) {
329 LASSERT(obj->oo_sa_hdl);
330 /* XXX: it should be possible to skip spill
331 * declaration if specific EA is part of
332 * bonus and doesn't grow */
333 dmu_tx_hold_spill(tx, db->db_object);
337 /* the object doesn't exist, but we've declared bonus
338 * in osd_declare_object_create() yet */
339 if (obj->oo_ea_in_bonus > DN_MAX_BONUSLEN) {
340 /* spill has been declared already */
341 } else if (obj->oo_ea_in_bonus + vallen > DN_MAX_BONUSLEN) {
342 /* we're about to exceed bonus, let's declare spill */
343 dmu_tx_hold_spill(tx, DMU_NEW_OBJECT);
345 obj->oo_ea_in_bonus += vallen;
348 int osd_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
349 const struct lu_buf *buf, const char *name,
350 int fl, struct thandle *handle)
352 struct osd_object *obj = osd_dt_obj(dt);
353 struct osd_thandle *oh;
356 LASSERT(handle != NULL);
357 oh = container_of0(handle, struct osd_thandle, ot_super);
359 down_read(&obj->oo_guard);
360 __osd_xattr_declare_set(env, obj, buf->lb_len, name, oh);
361 up_read(&obj->oo_guard);
367 * Set an extended attribute.
368 * This transaction must have called udmu_xattr_declare_set() first.
370 * Returns 0 on success or a negative error number on failure.
372 * No locking is done here.
375 __osd_sa_xattr_update(const struct lu_env *env, struct osd_object *obj,
376 struct osd_thandle *oh)
378 struct osd_device *osd = osd_obj2dev(obj);
384 LASSERT(obj->oo_sa_hdl);
385 LASSERT(obj->oo_sa_xattr);
387 /* Update the SA for additions, modifications, and removals. */
388 rc = -nvlist_size(obj->oo_sa_xattr, &sa_size, NV_ENCODE_XDR);
392 dxattr = osd_zio_buf_alloc(sa_size);
396 rc = -nvlist_pack(obj->oo_sa_xattr, &dxattr, &sa_size,
397 NV_ENCODE_XDR, KM_SLEEP);
401 rc = osd_object_sa_update(obj, SA_ZPL_DXATTR(osd), dxattr, sa_size, oh);
403 osd_zio_buf_free(dxattr, sa_size);
407 int __osd_sa_xattr_set(const struct lu_env *env, struct osd_object *obj,
408 const struct lu_buf *buf, const char *name, int fl,
409 struct osd_thandle *oh)
417 LASSERT(obj->oo_sa_hdl);
418 if (obj->oo_sa_xattr == NULL) {
419 rc = __osd_xattr_cache(env, obj);
424 LASSERT(obj->oo_sa_xattr);
425 /* Limited to 32k to keep nvpair memory allocations small */
426 if (buf->lb_len > DXATTR_MAX_ENTRY_SIZE) {
429 /* Prevent the DXATTR SA from consuming the entire SA
431 rc = -nvlist_size(obj->oo_sa_xattr, &size, NV_ENCODE_XDR);
435 if (size + buf->lb_len > DXATTR_MAX_SA_SIZE)
439 /* even in case of -EFBIG we must lookup xattr and check can we
440 * rewrite it then delete from SA */
441 rc = -nvlist_lookup_byte_array(obj->oo_sa_xattr, name, &nv_value,
444 if (fl & LU_XATTR_CREATE) {
446 } else if (too_big) {
447 rc = -nvlist_remove(obj->oo_sa_xattr, name,
448 DATA_TYPE_BYTE_ARRAY);
451 rc = __osd_sa_xattr_update(env, obj, oh);
452 return rc == 0 ? -EFBIG : rc;
454 } else if (rc == -ENOENT) {
455 if (fl & LU_XATTR_REPLACE)
463 /* Ensure xattr doesn't exist in ZAP */
464 if (obj->oo_xattr != ZFS_NO_OBJECT) {
465 struct osd_device *osd = osd_obj2dev(obj);
467 rc = -zap_lookup(osd->od_os, obj->oo_xattr,
470 rc = -dmu_object_free(osd->od_os, objid, oh->ot_tx);
472 zap_remove(osd->od_os, obj->oo_xattr,
477 rc = -nvlist_add_byte_array(obj->oo_sa_xattr, name,
478 (uchar_t *)buf->lb_buf, buf->lb_len);
482 rc = __osd_sa_xattr_update(env, obj, oh);
487 __osd_xattr_set(const struct lu_env *env, struct osd_object *obj,
488 const struct lu_buf *buf, const char *name, int fl,
489 struct osd_thandle *oh)
491 struct osd_device *osd = osd_obj2dev(obj);
492 dmu_buf_t *xa_zap_db = NULL;
493 dmu_buf_t *xa_data_db = NULL;
494 uint64_t xa_data_obj;
495 sa_handle_t *sa_hdl = NULL;
496 dmu_tx_t *tx = oh->ot_tx;
500 LASSERT(obj->oo_sa_hdl);
502 if (obj->oo_xattr == ZFS_NO_OBJECT) {
503 struct lu_attr *la = &osd_oti_get(env)->oti_la;
505 la->la_valid = LA_MODE;
506 la->la_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO;
507 rc = __osd_zap_create(env, osd, &xa_zap_db, tx, la, 0);
511 obj->oo_xattr = xa_zap_db->db_object;
512 rc = osd_object_sa_update(obj, SA_ZPL_XATTR(osd),
513 &obj->oo_xattr, 8, oh);
518 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
521 if (fl & LU_XATTR_CREATE) {
526 * Entry already exists.
527 * We'll truncate the existing object.
529 rc = __osd_obj2dbuf(env, osd->od_os, xa_data_obj,
534 rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL,
535 SA_HDL_PRIVATE, &sa_hdl);
539 rc = -sa_lookup(sa_hdl, SA_ZPL_SIZE(osd), &size, 8);
543 rc = -dmu_free_range(osd->od_os, xa_data_db->db_object,
544 0, DMU_OBJECT_END, tx);
547 } else if (rc == -ENOENT) {
548 struct lu_attr *la = &osd_oti_get(env)->oti_la;
550 * Entry doesn't exist, we need to create a new one and a new
551 * object to store the value.
553 if (fl & LU_XATTR_REPLACE) {
554 /* should be ENOATTR according to the
555 * man, but that is undefined here */
560 la->la_valid = LA_MODE;
561 la->la_mode = S_IFREG | S_IRUGO | S_IWUSR;
562 rc = __osd_object_create(env, obj, &xa_data_db, tx, la);
565 xa_data_obj = xa_data_db->db_object;
567 rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL,
568 SA_HDL_PRIVATE, &sa_hdl);
572 rc = -zap_add(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t),
573 1, &xa_data_obj, tx);
577 /* There was an error looking up the xattr name */
581 /* Finally write the xattr value */
582 dmu_write(osd->od_os, xa_data_obj, 0, buf->lb_len, buf->lb_buf, tx);
585 rc = -sa_update(sa_hdl, SA_ZPL_SIZE(osd), &size, 8, tx);
588 sa_handle_destroy(sa_hdl);
590 if (xa_data_db != NULL)
591 dmu_buf_rele(xa_data_db, FTAG);
592 if (xa_zap_db != NULL)
593 dmu_buf_rele(xa_zap_db, FTAG);
598 int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
599 const struct lu_buf *buf, const char *name, int fl,
600 struct thandle *handle)
602 struct osd_object *obj = osd_dt_obj(dt);
603 struct osd_thandle *oh;
607 LASSERT(handle != NULL);
608 LASSERT(osd_invariant(obj));
610 if (!osd_obj2dev(obj)->od_posix_acl &&
611 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
612 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
615 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_OVERFLOW) &&
616 strcmp(name, XATTR_NAME_LINK) == 0)
619 oh = container_of0(handle, struct osd_thandle, ot_super);
621 down_write(&obj->oo_guard);
622 CDEBUG(D_INODE, "Setting xattr %s with size %d\n",
623 name, (int)buf->lb_len);
624 rc = osd_xattr_set_internal(env, obj, buf, name, fl, oh);
625 up_write(&obj->oo_guard);
631 __osd_xattr_declare_del(const struct lu_env *env, struct osd_object *obj,
632 const char *name, struct osd_thandle *oh)
634 struct osd_device *osd = osd_obj2dev(obj);
635 dmu_tx_t *tx = oh->ot_tx;
636 uint64_t xa_data_obj;
639 /* update SA_ZPL_DXATTR if xattr was in SA */
640 dmu_tx_hold_sa(tx, obj->oo_sa_hdl, 0);
642 if (obj->oo_xattr == ZFS_NO_OBJECT)
645 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, 8, 1, &xa_data_obj);
649 * We'll delete the existing object and ZAP entry.
651 dmu_tx_hold_bonus(tx, xa_data_obj);
652 dmu_tx_hold_free(tx, xa_data_obj, 0, DMU_OBJECT_END);
653 dmu_tx_hold_zap(tx, obj->oo_xattr, FALSE, (char *) name);
655 } else if (rc == -ENOENT) {
657 * Entry doesn't exist, nothing to be changed.
662 /* An error happened */
666 int osd_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
667 const char *name, struct thandle *handle)
669 struct osd_object *obj = osd_dt_obj(dt);
670 struct osd_thandle *oh;
673 LASSERT(handle != NULL);
674 LASSERT(osd_invariant(obj));
676 oh = container_of0(handle, struct osd_thandle, ot_super);
677 LASSERT(oh->ot_tx != NULL);
678 LASSERT(obj->oo_db != NULL);
680 down_read(&obj->oo_guard);
681 if (likely(dt_object_exists(&obj->oo_dt) && !obj->oo_destroyed))
682 __osd_xattr_declare_del(env, obj, name, oh);
683 up_read(&obj->oo_guard);
688 static int __osd_sa_xattr_del(const struct lu_env *env, struct osd_object *obj,
689 const char *name, struct osd_thandle *oh)
693 if (obj->oo_sa_xattr == NULL) {
694 rc = __osd_xattr_cache(env, obj);
699 rc = -nvlist_remove(obj->oo_sa_xattr, name, DATA_TYPE_BYTE_ARRAY);
701 rc = __osd_sa_xattr_update(env, obj, oh);
705 static int __osd_xattr_del(const struct lu_env *env, struct osd_object *obj,
706 const char *name, struct osd_thandle *oh)
708 struct osd_device *osd = osd_obj2dev(obj);
709 uint64_t xa_data_obj;
712 if (unlikely(!dt_object_exists(&obj->oo_dt) || obj->oo_destroyed))
715 /* try remove xattr from SA at first */
716 rc = __osd_sa_xattr_del(env, obj, name, oh);
720 if (obj->oo_xattr == ZFS_NO_OBJECT)
723 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
727 } else if (rc == 0) {
730 * We'll delete the existing object and ZAP entry.
732 rc = -dmu_object_free(osd->od_os, xa_data_obj, oh->ot_tx);
736 rc = -zap_remove(osd->od_os, obj->oo_xattr, name, oh->ot_tx);
742 int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
743 const char *name, struct thandle *handle)
745 struct osd_object *obj = osd_dt_obj(dt);
746 struct osd_thandle *oh;
750 LASSERT(handle != NULL);
751 LASSERT(obj->oo_db != NULL);
752 LASSERT(osd_invariant(obj));
753 LASSERT(dt_object_exists(dt));
754 oh = container_of0(handle, struct osd_thandle, ot_super);
755 LASSERT(oh->ot_tx != NULL);
757 if (!osd_obj2dev(obj)->od_posix_acl &&
758 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
759 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
762 down_write(&obj->oo_guard);
763 rc = __osd_xattr_del(env, obj, name, oh);
764 up_write(&obj->oo_guard);
769 void osd_declare_xattrs_destroy(const struct lu_env *env,
770 struct osd_object *obj, struct osd_thandle *oh)
772 struct osd_device *osd = osd_obj2dev(obj);
773 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
774 uint64_t oid = obj->oo_xattr, xid;
775 dmu_tx_t *tx = oh->ot_tx;
779 if (oid == ZFS_NO_OBJECT)
780 return; /* Nothing to do for SA xattrs */
782 /* Declare to free the ZAP holding xattrs */
783 dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END);
785 rc = osd_zap_cursor_init(&zc, osd->od_os, oid, 0);
789 while (zap_cursor_retrieve(zc, za) == 0) {
790 LASSERT(za->za_num_integers == 1);
791 LASSERT(za->za_integer_length == sizeof(uint64_t));
793 rc = -zap_lookup(osd->od_os, oid, za->za_name,
794 sizeof(uint64_t), 1, &xid);
796 CERROR("%s: xattr %s lookup failed: rc = %d\n",
797 osd->od_svname, za->za_name, rc);
800 dmu_tx_hold_free(tx, xid, 0, DMU_OBJECT_END);
802 zap_cursor_advance(zc);
805 osd_zap_cursor_fini(zc);
807 if (rc && tx->tx_err == 0)
811 int osd_xattrs_destroy(const struct lu_env *env,
812 struct osd_object *obj, struct osd_thandle *oh)
814 struct osd_device *osd = osd_obj2dev(obj);
815 dmu_tx_t *tx = oh->ot_tx;
816 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
821 /* The transaction must have been assigned to a transaction group. */
822 LASSERT(tx->tx_txg != 0);
824 if (obj->oo_xattr == ZFS_NO_OBJECT)
825 return 0; /* Nothing to do for SA xattrs */
827 /* Free the ZAP holding the xattrs */
828 rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0);
832 while (zap_cursor_retrieve(zc, za) == 0) {
833 LASSERT(za->za_num_integers == 1);
834 LASSERT(za->za_integer_length == sizeof(uint64_t));
836 rc = -zap_lookup(osd->od_os, obj->oo_xattr, za->za_name,
837 sizeof(uint64_t), 1, &xid);
839 CERROR("%s: lookup xattr %s failed: rc = %d\n",
840 osd->od_svname, za->za_name, rc);
842 rc = -dmu_object_free(osd->od_os, xid, tx);
844 CERROR("%s: free xattr %s failed: rc = %d\n",
845 osd->od_svname, za->za_name, rc);
847 zap_cursor_advance(zc);
849 osd_zap_cursor_fini(zc);
851 rc = -dmu_object_free(osd->od_os, obj->oo_xattr, tx);
853 CERROR("%s: free xattr "LPU64" failed: rc = %d\n",
854 osd->od_svname, obj->oo_xattr, rc);
860 osd_sa_xattr_list(const struct lu_env *env, struct osd_object *obj,
861 const struct lu_buf *lb)
863 nvpair_t *nvp = NULL;
864 int len, counted = 0;
867 if (obj->oo_sa_xattr == NULL) {
868 rc = __osd_xattr_cache(env, obj);
873 LASSERT(obj->oo_sa_xattr);
875 while ((nvp = nvlist_next_nvpair(obj->oo_sa_xattr, nvp)) != NULL) {
876 const char *name = nvpair_name(nvp);
878 if (!osd_obj2dev(obj)->od_posix_acl &&
879 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
880 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
884 if (lb->lb_buf != NULL) {
885 if (counted + len + 1 > lb->lb_len)
888 memcpy(lb->lb_buf + counted, name, len + 1);
895 int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
896 const struct lu_buf *lb)
898 struct osd_object *obj = osd_dt_obj(dt);
899 struct osd_device *osd = osd_obj2dev(obj);
900 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
905 LASSERT(obj->oo_db != NULL);
906 LASSERT(osd_invariant(obj));
907 LASSERT(dt_object_exists(dt));
909 down_read(&obj->oo_guard);
911 rc = osd_sa_xattr_list(env, obj, lb);
917 /* continue with dnode xattr if any */
918 if (obj->oo_xattr == ZFS_NO_OBJECT)
919 GOTO(out, rc = counted);
921 rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0);
925 while ((rc = -zap_cursor_retrieve(zc, za)) == 0) {
926 if (!osd_obj2dev(obj)->od_posix_acl &&
927 (strcmp(za->za_name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
928 strcmp(za->za_name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0)) {
929 zap_cursor_advance(zc);
933 rc = strlen(za->za_name);
934 if (lb->lb_buf != NULL) {
935 if (counted + rc + 1 > lb->lb_len)
936 GOTO(out_fini, rc = -ERANGE);
938 memcpy(lb->lb_buf + counted, za->za_name, rc + 1);
942 zap_cursor_advance(zc);
944 if (rc == -ENOENT) /* no more kes in the index */
946 else if (unlikely(rc < 0))
951 osd_zap_cursor_fini(zc);
953 up_read(&obj->oo_guard);