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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/osd-zfs/osd_xattr.c
33 * functions to manipulate extended attributes and system attributes
35 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
36 * Author: Mike Pershin <tappro@whamcloud.com>
39 #define DEBUG_SUBSYSTEM S_OSD
41 #include <lustre_ver.h>
42 #include <libcfs/libcfs.h>
43 #include <obd_support.h>
44 #include <lustre_net.h>
46 #include <obd_class.h>
47 #include <lustre_disk.h>
48 #include <lustre_fid.h>
50 #include "osd_internal.h"
52 #include <sys/dnode.h>
57 #include <sys/spa_impl.h>
58 #include <sys/zfs_znode.h>
59 #include <sys/dmu_tx.h>
60 #include <sys/dmu_objset.h>
61 #include <sys/dsl_prop.h>
62 #include <sys/sa_impl.h>
65 #include <linux/posix_acl_xattr.h>
68 int __osd_xattr_load(struct osd_device *osd, uint64_t dnode, nvlist_t **sa)
74 if (unlikely(dnode == ZFS_NO_OBJECT))
77 rc = -sa_handle_get(osd->od_os, dnode, NULL, SA_HDL_PRIVATE, &sa_hdl);
81 rc = -sa_size(sa_hdl, SA_ZPL_DXATTR(osd), &size);
84 rc = -nvlist_alloc(sa, NV_UNIQUE_NAME, KM_SLEEP);
88 buf = osd_zio_buf_alloc(size);
93 rc = -sa_lookup(sa_hdl, SA_ZPL_DXATTR(osd), buf, size);
95 rc = -nvlist_unpack(buf, size, sa, KM_SLEEP);
96 osd_zio_buf_free(buf, size);
98 sa_handle_destroy(sa_hdl);
103 static inline int __osd_xattr_cache(const struct lu_env *env,
104 struct osd_object *obj)
106 LASSERT(obj->oo_sa_xattr == NULL);
107 LASSERT(obj->oo_db != NULL);
109 return __osd_xattr_load(osd_obj2dev(obj), obj->oo_db->db_object,
114 __osd_sa_xattr_get(const struct lu_env *env, struct osd_object *obj,
115 const struct lu_buf *buf, const char *name, int *sizep)
120 LASSERT(obj->oo_sa_hdl);
122 if (obj->oo_sa_xattr == NULL) {
123 rc = __osd_xattr_cache(env, obj);
128 LASSERT(obj->oo_sa_xattr);
129 rc = -nvlist_lookup_byte_array(obj->oo_sa_xattr, name, &nv_value,
134 if (buf == NULL || buf->lb_buf == NULL) {
135 /* return the required size by *sizep */
139 if (*sizep > buf->lb_len)
140 return -ERANGE; /* match ldiskfs error */
142 memcpy(buf->lb_buf, nv_value, *sizep);
146 int __osd_xattr_get_large(const struct lu_env *env, struct osd_device *osd,
147 uint64_t xattr, struct lu_buf *buf,
148 const char *name, int *sizep)
150 dmu_buf_t *xa_data_db;
151 sa_handle_t *sa_hdl = NULL;
152 uint64_t xa_data_obj, size;
155 /* are there any extended attributes? */
156 if (xattr == ZFS_NO_OBJECT)
159 /* Lookup the object number containing the xattr data */
160 rc = -zap_lookup(osd->od_os, xattr, name, sizeof(uint64_t), 1,
165 rc = __osd_obj2dbuf(env, osd->od_os, xa_data_obj, &xa_data_db);
169 rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL, SA_HDL_PRIVATE,
174 /* Get the xattr value length / object size */
175 rc = -sa_lookup(sa_hdl, SA_ZPL_SIZE(osd), &size, 8);
179 if (size > INT_MAX) {
186 if (buf == NULL || buf->lb_buf == NULL) {
187 /* We only need to return the required size */
190 if (*sizep > buf->lb_len) {
191 rc = -ERANGE; /* match ldiskfs error */
195 rc = -dmu_read(osd->od_os, xa_data_db->db_object, 0,
196 size, buf->lb_buf, DMU_READ_PREFETCH);
199 sa_handle_destroy(sa_hdl);
201 dmu_buf_rele(xa_data_db, FTAG);
207 * Copy an extended attribute into the buffer provided, or compute
208 * the required buffer size if \a buf is NULL.
210 * On success, the number of bytes used or required is stored in \a sizep.
212 * Note that no locking is done here.
214 * \param[in] env execution environment
215 * \param[in] obj object for which to retrieve xattr
216 * \param[out] buf buffer to store xattr value in
217 * \param[in] name name of xattr to copy
218 * \param[out] sizep bytes used or required to store xattr
220 * \retval 0 on success
221 * \retval negative negated errno on failure
223 int __osd_xattr_get(const struct lu_env *env, struct osd_object *obj,
224 struct lu_buf *buf, const char *name, int *sizep)
228 if (unlikely(!dt_object_exists(&obj->oo_dt) || obj->oo_destroyed))
231 /* check SA_ZPL_DXATTR first then fallback to directory xattr */
232 rc = __osd_sa_xattr_get(env, obj, buf, name, sizep);
236 return __osd_xattr_get_large(env, osd_obj2dev(obj), obj->oo_xattr,
240 int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
241 struct lu_buf *buf, const char *name)
243 struct osd_object *obj = osd_dt_obj(dt);
247 LASSERT(obj->oo_db != NULL);
248 LASSERT(osd_invariant(obj));
250 if (!osd_obj2dev(obj)->od_posix_acl &&
251 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
252 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
255 down_read(&obj->oo_guard);
256 rc = __osd_xattr_get(env, obj, buf, name, &size);
257 up_read(&obj->oo_guard);
266 /* the function is used to declare EAs when SA is not supported */
267 void __osd_xattr_declare_legacy(const struct lu_env *env,
268 struct osd_object *obj,
269 int vallen, const char *name,
270 struct osd_thandle *oh)
272 struct osd_device *osd = osd_obj2dev(obj);
273 dmu_tx_t *tx = oh->ot_tx;
274 uint64_t xa_data_obj;
277 if (obj->oo_xattr == ZFS_NO_OBJECT) {
278 /* xattr zap + entry */
279 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, (char *) name);
280 /* xattr value obj */
281 dmu_tx_hold_sa_create(tx, ZFS_SA_BASE_ATTR_SIZE);
282 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, vallen);
286 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
290 * Entry already exists.
291 * We'll truncate the existing object.
293 dmu_tx_hold_bonus(tx, xa_data_obj);
294 dmu_tx_hold_free(tx, xa_data_obj, vallen, DMU_OBJECT_END);
295 dmu_tx_hold_write(tx, xa_data_obj, 0, vallen);
296 } else if (rc == -ENOENT) {
298 * Entry doesn't exist, we need to create a new one and a new
299 * object to store the value.
301 dmu_tx_hold_bonus(tx, obj->oo_xattr);
302 dmu_tx_hold_zap(tx, obj->oo_xattr, TRUE, (char *) name);
303 dmu_tx_hold_sa_create(tx, ZFS_SA_BASE_ATTR_SIZE);
304 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, vallen);
308 void __osd_xattr_declare_set(const struct lu_env *env, struct osd_object *obj,
309 int vallen, const char *name,
310 struct osd_thandle *oh)
312 dmu_buf_t *db = obj->oo_db;
313 dmu_tx_t *tx = oh->ot_tx;
315 if (unlikely(obj->oo_destroyed))
318 if (unlikely(!osd_obj2dev(obj)->od_xattr_in_sa)) {
319 __osd_xattr_declare_legacy(env, obj, vallen, name, oh);
323 /* declare EA in SA */
324 if (dt_object_exists(&obj->oo_dt)) {
325 LASSERT(obj->oo_sa_hdl);
326 /* XXX: it should be possible to skip spill
327 * declaration if specific EA is part of
328 * bonus and doesn't grow */
329 dmu_tx_hold_spill(tx, db->db_object);
333 /* the object doesn't exist, but we've declared bonus
334 * in osd_declare_object_create() yet */
335 if (obj->oo_ea_in_bonus > DN_MAX_BONUSLEN) {
336 /* spill has been declared already */
337 } else if (obj->oo_ea_in_bonus + vallen > DN_MAX_BONUSLEN) {
338 /* we're about to exceed bonus, let's declare spill */
339 dmu_tx_hold_spill(tx, DMU_NEW_OBJECT);
341 obj->oo_ea_in_bonus += vallen;
344 int osd_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
345 const struct lu_buf *buf, const char *name,
346 int fl, struct thandle *handle)
348 struct osd_object *obj = osd_dt_obj(dt);
349 struct osd_thandle *oh;
352 LASSERT(handle != NULL);
353 oh = container_of0(handle, struct osd_thandle, ot_super);
355 down_read(&obj->oo_guard);
356 __osd_xattr_declare_set(env, obj, buf->lb_len, name, oh);
357 up_read(&obj->oo_guard);
363 * Set an extended attribute.
364 * This transaction must have called udmu_xattr_declare_set() first.
366 * Returns 0 on success or a negative error number on failure.
368 * No locking is done here.
370 int __osd_sa_xattr_update(const struct lu_env *env, struct osd_object *obj,
371 struct osd_thandle *oh)
373 struct osd_device *osd = osd_obj2dev(obj);
379 LASSERT(obj->oo_sa_hdl);
380 LASSERT(obj->oo_sa_xattr);
382 /* Update the SA for additions, modifications, and removals. */
383 rc = -nvlist_size(obj->oo_sa_xattr, &sa_size, NV_ENCODE_XDR);
387 dxattr = osd_zio_buf_alloc(sa_size);
391 rc = -nvlist_pack(obj->oo_sa_xattr, &dxattr, &sa_size,
392 NV_ENCODE_XDR, KM_SLEEP);
396 rc = osd_object_sa_update(obj, SA_ZPL_DXATTR(osd), dxattr, sa_size, oh);
398 osd_zio_buf_free(dxattr, sa_size);
402 int __osd_sa_xattr_set(const struct lu_env *env, struct osd_object *obj,
403 const struct lu_buf *buf, const char *name, int fl,
404 struct osd_thandle *oh)
412 LASSERT(obj->oo_sa_hdl);
413 if (obj->oo_sa_xattr == NULL) {
414 rc = __osd_xattr_cache(env, obj);
419 LASSERT(obj->oo_sa_xattr);
420 /* Limited to 32k to keep nvpair memory allocations small */
421 if (buf->lb_len > DXATTR_MAX_ENTRY_SIZE) {
424 /* Prevent the DXATTR SA from consuming the entire SA
426 rc = -nvlist_size(obj->oo_sa_xattr, &size, NV_ENCODE_XDR);
430 if (size + buf->lb_len > DXATTR_MAX_SA_SIZE)
434 /* even in case of -EFBIG we must lookup xattr and check can we
435 * rewrite it then delete from SA */
436 rc = -nvlist_lookup_byte_array(obj->oo_sa_xattr, name, &nv_value,
439 if (fl & LU_XATTR_CREATE) {
441 } else if (too_big) {
442 rc = -nvlist_remove(obj->oo_sa_xattr, name,
443 DATA_TYPE_BYTE_ARRAY);
446 rc = __osd_sa_xattr_update(env, obj, oh);
447 return rc == 0 ? -EFBIG : rc;
449 } else if (rc == -ENOENT) {
450 if (fl & LU_XATTR_REPLACE)
458 /* Ensure xattr doesn't exist in ZAP */
459 if (obj->oo_xattr != ZFS_NO_OBJECT) {
460 struct osd_device *osd = osd_obj2dev(obj);
462 rc = -zap_lookup(osd->od_os, obj->oo_xattr,
465 rc = -dmu_object_free(osd->od_os, objid, oh->ot_tx);
467 zap_remove(osd->od_os, obj->oo_xattr,
472 rc = -nvlist_add_byte_array(obj->oo_sa_xattr, name,
473 (uchar_t *)buf->lb_buf, buf->lb_len);
477 rc = __osd_sa_xattr_update(env, obj, oh);
482 __osd_xattr_set(const struct lu_env *env, struct osd_object *obj,
483 const struct lu_buf *buf, const char *name, int fl,
484 struct osd_thandle *oh)
486 struct osd_device *osd = osd_obj2dev(obj);
487 dmu_buf_t *xa_zap_db = NULL;
488 dmu_buf_t *xa_data_db = NULL;
489 uint64_t xa_data_obj;
490 sa_handle_t *sa_hdl = NULL;
491 dmu_tx_t *tx = oh->ot_tx;
495 LASSERT(obj->oo_sa_hdl);
497 if (obj->oo_xattr == ZFS_NO_OBJECT) {
498 struct lu_attr *la = &osd_oti_get(env)->oti_la;
500 la->la_valid = LA_MODE;
501 la->la_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO;
502 rc = __osd_zap_create(env, osd, &xa_zap_db, tx, la, 0);
506 obj->oo_xattr = xa_zap_db->db_object;
507 rc = osd_object_sa_update(obj, SA_ZPL_XATTR(osd),
508 &obj->oo_xattr, 8, oh);
513 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
516 if (fl & LU_XATTR_CREATE) {
521 * Entry already exists.
522 * We'll truncate the existing object.
524 rc = __osd_obj2dbuf(env, osd->od_os, xa_data_obj,
529 rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL,
530 SA_HDL_PRIVATE, &sa_hdl);
534 rc = -sa_lookup(sa_hdl, SA_ZPL_SIZE(osd), &size, 8);
538 rc = -dmu_free_range(osd->od_os, xa_data_db->db_object,
539 0, DMU_OBJECT_END, tx);
542 } else if (rc == -ENOENT) {
543 struct lu_attr *la = &osd_oti_get(env)->oti_la;
545 * Entry doesn't exist, we need to create a new one and a new
546 * object to store the value.
548 if (fl & LU_XATTR_REPLACE) {
549 /* should be ENOATTR according to the
550 * man, but that is undefined here */
555 la->la_valid = LA_MODE;
556 la->la_mode = S_IFREG | S_IRUGO | S_IWUSR;
557 rc = __osd_object_create(env, obj, &xa_data_db, tx, la);
560 xa_data_obj = xa_data_db->db_object;
562 rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL,
563 SA_HDL_PRIVATE, &sa_hdl);
567 rc = -zap_add(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t),
568 1, &xa_data_obj, tx);
572 /* There was an error looking up the xattr name */
576 /* Finally write the xattr value */
577 dmu_write(osd->od_os, xa_data_obj, 0, buf->lb_len, buf->lb_buf, tx);
580 rc = -sa_update(sa_hdl, SA_ZPL_SIZE(osd), &size, 8, tx);
583 sa_handle_destroy(sa_hdl);
585 if (xa_data_db != NULL)
586 dmu_buf_rele(xa_data_db, FTAG);
587 if (xa_zap_db != NULL)
588 dmu_buf_rele(xa_zap_db, FTAG);
593 int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
594 const struct lu_buf *buf, const char *name, int fl,
595 struct thandle *handle)
597 struct osd_object *obj = osd_dt_obj(dt);
598 struct osd_thandle *oh;
602 LASSERT(handle != NULL);
603 LASSERT(osd_invariant(obj));
605 if (!osd_obj2dev(obj)->od_posix_acl &&
606 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
607 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
610 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_OVERFLOW) &&
611 strcmp(name, XATTR_NAME_LINK) == 0)
614 oh = container_of0(handle, struct osd_thandle, ot_super);
616 down_write(&obj->oo_guard);
617 CDEBUG(D_INODE, "Setting xattr %s with size %d\n",
618 name, (int)buf->lb_len);
619 rc = osd_xattr_set_internal(env, obj, buf, name, fl, oh);
620 up_write(&obj->oo_guard);
626 __osd_xattr_declare_del(const struct lu_env *env, struct osd_object *obj,
627 const char *name, struct osd_thandle *oh)
629 struct osd_device *osd = osd_obj2dev(obj);
630 dmu_tx_t *tx = oh->ot_tx;
631 uint64_t xa_data_obj;
634 /* update SA_ZPL_DXATTR if xattr was in SA */
635 dmu_tx_hold_sa(tx, obj->oo_sa_hdl, 0);
637 if (obj->oo_xattr == ZFS_NO_OBJECT)
640 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, 8, 1, &xa_data_obj);
644 * We'll delete the existing object and ZAP entry.
646 dmu_tx_hold_bonus(tx, xa_data_obj);
647 dmu_tx_hold_free(tx, xa_data_obj, 0, DMU_OBJECT_END);
648 dmu_tx_hold_zap(tx, obj->oo_xattr, FALSE, (char *) name);
650 } else if (rc == -ENOENT) {
652 * Entry doesn't exist, nothing to be changed.
657 /* An error happened */
661 int osd_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
662 const char *name, struct thandle *handle)
664 struct osd_object *obj = osd_dt_obj(dt);
665 struct osd_thandle *oh;
668 LASSERT(handle != NULL);
669 LASSERT(osd_invariant(obj));
671 oh = container_of0(handle, struct osd_thandle, ot_super);
672 LASSERT(oh->ot_tx != NULL);
673 LASSERT(obj->oo_db != NULL);
675 down_read(&obj->oo_guard);
676 if (likely(dt_object_exists(&obj->oo_dt) && !obj->oo_destroyed))
677 __osd_xattr_declare_del(env, obj, name, oh);
678 up_read(&obj->oo_guard);
683 static int __osd_sa_xattr_del(const struct lu_env *env, struct osd_object *obj,
684 const char *name, struct osd_thandle *oh)
688 if (obj->oo_sa_xattr == NULL) {
689 rc = __osd_xattr_cache(env, obj);
694 rc = -nvlist_remove(obj->oo_sa_xattr, name, DATA_TYPE_BYTE_ARRAY);
696 rc = __osd_sa_xattr_update(env, obj, oh);
700 static int __osd_xattr_del(const struct lu_env *env, struct osd_object *obj,
701 const char *name, struct osd_thandle *oh)
703 struct osd_device *osd = osd_obj2dev(obj);
704 uint64_t xa_data_obj;
707 if (unlikely(!dt_object_exists(&obj->oo_dt) || obj->oo_destroyed))
710 /* try remove xattr from SA at first */
711 rc = __osd_sa_xattr_del(env, obj, name, oh);
715 if (obj->oo_xattr == ZFS_NO_OBJECT)
718 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
722 } else if (rc == 0) {
725 * We'll delete the existing object and ZAP entry.
727 rc = -dmu_object_free(osd->od_os, xa_data_obj, oh->ot_tx);
731 rc = -zap_remove(osd->od_os, obj->oo_xattr, name, oh->ot_tx);
737 int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
738 const char *name, struct thandle *handle)
740 struct osd_object *obj = osd_dt_obj(dt);
741 struct osd_thandle *oh;
745 LASSERT(handle != NULL);
746 LASSERT(obj->oo_db != NULL);
747 LASSERT(osd_invariant(obj));
748 LASSERT(dt_object_exists(dt));
749 oh = container_of0(handle, struct osd_thandle, ot_super);
750 LASSERT(oh->ot_tx != NULL);
752 if (!osd_obj2dev(obj)->od_posix_acl &&
753 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
754 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
757 down_write(&obj->oo_guard);
758 rc = __osd_xattr_del(env, obj, name, oh);
759 up_write(&obj->oo_guard);
764 void osd_declare_xattrs_destroy(const struct lu_env *env,
765 struct osd_object *obj, struct osd_thandle *oh)
767 struct osd_device *osd = osd_obj2dev(obj);
768 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
769 uint64_t oid = obj->oo_xattr, xid;
770 dmu_tx_t *tx = oh->ot_tx;
774 if (oid == ZFS_NO_OBJECT)
775 return; /* Nothing to do for SA xattrs */
777 /* Declare to free the ZAP holding xattrs */
778 dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END);
780 rc = osd_zap_cursor_init(&zc, osd->od_os, oid, 0);
784 while (zap_cursor_retrieve(zc, za) == 0) {
785 LASSERT(za->za_num_integers == 1);
786 LASSERT(za->za_integer_length == sizeof(uint64_t));
788 rc = -zap_lookup(osd->od_os, oid, za->za_name,
789 sizeof(uint64_t), 1, &xid);
791 CERROR("%s: xattr %s lookup failed: rc = %d\n",
792 osd->od_svname, za->za_name, rc);
795 dmu_tx_hold_free(tx, xid, 0, DMU_OBJECT_END);
797 zap_cursor_advance(zc);
800 osd_zap_cursor_fini(zc);
802 if (rc && tx->tx_err == 0)
806 int osd_xattrs_destroy(const struct lu_env *env,
807 struct osd_object *obj, struct osd_thandle *oh)
809 struct osd_device *osd = osd_obj2dev(obj);
810 dmu_tx_t *tx = oh->ot_tx;
811 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
816 /* The transaction must have been assigned to a transaction group. */
817 LASSERT(tx->tx_txg != 0);
819 if (obj->oo_xattr == ZFS_NO_OBJECT)
820 return 0; /* Nothing to do for SA xattrs */
822 /* Free the ZAP holding the xattrs */
823 rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0);
827 while (zap_cursor_retrieve(zc, za) == 0) {
828 LASSERT(za->za_num_integers == 1);
829 LASSERT(za->za_integer_length == sizeof(uint64_t));
831 rc = -zap_lookup(osd->od_os, obj->oo_xattr, za->za_name,
832 sizeof(uint64_t), 1, &xid);
834 CERROR("%s: lookup xattr %s failed: rc = %d\n",
835 osd->od_svname, za->za_name, rc);
837 rc = -dmu_object_free(osd->od_os, xid, tx);
839 CERROR("%s: free xattr %s failed: rc = %d\n",
840 osd->od_svname, za->za_name, rc);
842 zap_cursor_advance(zc);
844 osd_zap_cursor_fini(zc);
846 rc = -dmu_object_free(osd->od_os, obj->oo_xattr, tx);
848 CERROR("%s: free xattr %llu failed: rc = %d\n",
849 osd->od_svname, obj->oo_xattr, rc);
855 osd_sa_xattr_list(const struct lu_env *env, struct osd_object *obj,
856 const struct lu_buf *lb)
858 nvpair_t *nvp = NULL;
859 int len, counted = 0;
862 if (obj->oo_sa_xattr == NULL) {
863 rc = __osd_xattr_cache(env, obj);
868 LASSERT(obj->oo_sa_xattr);
870 while ((nvp = nvlist_next_nvpair(obj->oo_sa_xattr, nvp)) != NULL) {
871 const char *name = nvpair_name(nvp);
873 if (!osd_obj2dev(obj)->od_posix_acl &&
874 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
875 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
879 if (lb->lb_buf != NULL) {
880 if (counted + len + 1 > lb->lb_len)
883 memcpy(lb->lb_buf + counted, name, len + 1);
890 int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
891 const struct lu_buf *lb)
893 struct osd_object *obj = osd_dt_obj(dt);
894 struct osd_device *osd = osd_obj2dev(obj);
895 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
900 LASSERT(obj->oo_db != NULL);
901 LASSERT(osd_invariant(obj));
902 LASSERT(dt_object_exists(dt));
904 down_read(&obj->oo_guard);
906 rc = osd_sa_xattr_list(env, obj, lb);
912 /* continue with dnode xattr if any */
913 if (obj->oo_xattr == ZFS_NO_OBJECT)
914 GOTO(out, rc = counted);
916 rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0);
920 while ((rc = -zap_cursor_retrieve(zc, za)) == 0) {
921 if (!osd_obj2dev(obj)->od_posix_acl &&
922 (strcmp(za->za_name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
923 strcmp(za->za_name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0)) {
924 zap_cursor_advance(zc);
928 rc = strlen(za->za_name);
929 if (lb->lb_buf != NULL) {
930 if (counted + rc + 1 > lb->lb_len)
931 GOTO(out_fini, rc = -ERANGE);
933 memcpy(lb->lb_buf + counted, za->za_name, rc + 1);
937 zap_cursor_advance(zc);
939 if (rc == -ENOENT) /* no more kes in the index */
941 else if (unlikely(rc < 0))
946 osd_zap_cursor_fini(zc);
948 up_read(&obj->oo_guard);