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, 2016, 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, sa_handle_t *hdl, nvlist_t **sa)
73 rc = -sa_size(hdl, SA_ZPL_DXATTR(osd), &size);
76 rc = -nvlist_alloc(sa, NV_UNIQUE_NAME, KM_SLEEP);
80 buf = osd_zio_buf_alloc(size);
85 rc = -sa_lookup(hdl, SA_ZPL_DXATTR(osd), buf, size);
87 rc = -nvlist_unpack(buf, size, sa, KM_SLEEP);
88 osd_zio_buf_free(buf, size);
94 static inline int __osd_xattr_cache(struct osd_object *obj)
96 LASSERT(obj->oo_sa_hdl);
97 if (obj->oo_sa_xattr != NULL)
99 return __osd_xattr_load(osd_obj2dev(obj),
100 obj->oo_sa_hdl, &obj->oo_sa_xattr);
104 __osd_sa_xattr_get(const struct lu_env *env, struct osd_object *obj,
105 const struct lu_buf *buf, const char *name, int *sizep)
110 rc = __osd_xattr_cache(obj);
114 LASSERT(obj->oo_sa_xattr);
115 rc = -nvlist_lookup_byte_array(obj->oo_sa_xattr, name,
120 if (buf == NULL || buf->lb_buf == NULL) {
121 /* return the required size by *sizep */
125 if (*sizep > buf->lb_len)
126 return -ERANGE; /* match ldiskfs error */
128 memcpy(buf->lb_buf, nv_value, *sizep);
132 int __osd_xattr_get_large(const struct lu_env *env, struct osd_device *osd,
133 uint64_t xattr, struct lu_buf *buf,
134 const char *name, int *sizep)
137 sa_handle_t *sa_hdl = NULL;
138 uint64_t xa_data_obj, size;
141 /* are there any extended attributes? */
142 if (xattr == ZFS_NO_OBJECT)
145 /* Lookup the object number containing the xattr data */
146 rc = -zap_lookup(osd->od_os, xattr, name, sizeof(uint64_t), 1,
151 rc = __osd_obj2dnode(osd->od_os, xa_data_obj, &xa_data_dn);
155 rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL, SA_HDL_PRIVATE,
160 /* Get the xattr value length / object size */
161 rc = -sa_lookup(sa_hdl, SA_ZPL_SIZE(osd), &size, 8);
165 if (size > INT_MAX) {
172 if (buf == NULL || buf->lb_buf == NULL) {
173 /* We only need to return the required size */
176 if (*sizep > buf->lb_len) {
177 rc = -ERANGE; /* match ldiskfs error */
181 rc = -dmu_read(osd->od_os, xa_data_dn->dn_object, 0,
182 size, buf->lb_buf, DMU_READ_PREFETCH);
185 sa_handle_destroy(sa_hdl);
187 osd_dnode_rele(xa_data_dn);
193 * Copy an extended attribute into the buffer provided, or compute
194 * the required buffer size if \a buf is NULL.
196 * On success, the number of bytes used or required is stored in \a sizep.
198 * Note that no locking is done here.
200 * \param[in] env execution environment
201 * \param[in] obj object for which to retrieve xattr
202 * \param[out] buf buffer to store xattr value in
203 * \param[in] name name of xattr to copy
204 * \param[out] sizep bytes used or required to store xattr
206 * \retval 0 on success
207 * \retval negative negated errno on failure
209 int __osd_xattr_get(const struct lu_env *env, struct osd_object *obj,
210 struct lu_buf *buf, const char *name, int *sizep)
214 if (unlikely(!dt_object_exists(&obj->oo_dt) || obj->oo_destroyed))
217 /* check SA_ZPL_DXATTR first then fallback to directory xattr */
218 rc = __osd_sa_xattr_get(env, obj, buf, name, sizep);
222 return __osd_xattr_get_large(env, osd_obj2dev(obj), obj->oo_xattr,
226 int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
227 struct lu_buf *buf, const char *name)
229 struct osd_object *obj = osd_dt_obj(dt);
233 LASSERT(obj->oo_dn != NULL);
234 LASSERT(osd_invariant(obj));
236 if (!osd_obj2dev(obj)->od_posix_acl &&
237 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
238 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
241 down_read(&obj->oo_guard);
242 rc = __osd_xattr_get(env, obj, buf, name, &size);
243 up_read(&obj->oo_guard);
252 /* the function is used to declare EAs when SA is not supported */
253 void __osd_xattr_declare_legacy(const struct lu_env *env,
254 struct osd_object *obj,
255 int vallen, const char *name,
256 struct osd_thandle *oh)
258 struct osd_device *osd = osd_obj2dev(obj);
259 dmu_tx_t *tx = oh->ot_tx;
260 uint64_t xa_data_obj;
263 if (obj->oo_xattr == ZFS_NO_OBJECT) {
264 /* xattr zap + entry */
265 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, (char *) name);
266 /* xattr value obj */
267 dmu_tx_hold_sa_create(tx, ZFS_SA_BASE_ATTR_SIZE);
268 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, vallen);
272 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
276 * Entry already exists.
277 * We'll truncate the existing object.
279 dmu_tx_hold_bonus(tx, xa_data_obj);
280 dmu_tx_hold_free(tx, xa_data_obj, vallen, DMU_OBJECT_END);
281 dmu_tx_hold_write(tx, xa_data_obj, 0, vallen);
282 } else if (rc == -ENOENT) {
284 * Entry doesn't exist, we need to create a new one and a new
285 * object to store the value.
287 dmu_tx_hold_bonus(tx, obj->oo_xattr);
288 dmu_tx_hold_zap(tx, obj->oo_xattr, TRUE, (char *) name);
289 dmu_tx_hold_sa_create(tx, ZFS_SA_BASE_ATTR_SIZE);
290 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, vallen);
294 void __osd_xattr_declare_set(const struct lu_env *env, struct osd_object *obj,
295 int vallen, const char *name,
296 struct osd_thandle *oh)
298 dmu_tx_t *tx = oh->ot_tx;
301 if (unlikely(obj->oo_destroyed))
304 if (unlikely(!osd_obj2dev(obj)->od_xattr_in_sa)) {
305 __osd_xattr_declare_legacy(env, obj, vallen, name, oh);
309 /* declare EA in SA */
310 if (dt_object_exists(&obj->oo_dt)) {
311 LASSERT(obj->oo_sa_hdl);
312 /* XXX: it should be possible to skip spill
313 * declaration if specific EA is part of
314 * bonus and doesn't grow */
315 dmu_tx_hold_spill(tx, obj->oo_dn->dn_object);
319 bonuslen = osd_obj_bonuslen(obj);
321 /* the object doesn't exist, but we've declared bonus
322 * in osd_declare_object_create() yet */
323 if (obj->oo_ea_in_bonus > bonuslen) {
324 /* spill has been declared already */
325 } else if (obj->oo_ea_in_bonus + vallen > bonuslen) {
326 /* we're about to exceed bonus, let's declare spill */
327 dmu_tx_hold_spill(tx, DMU_NEW_OBJECT);
329 obj->oo_ea_in_bonus += vallen;
332 int osd_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
333 const struct lu_buf *buf, const char *name,
334 int fl, struct thandle *handle)
336 struct osd_object *obj = osd_dt_obj(dt);
337 struct osd_thandle *oh;
340 LASSERT(handle != NULL);
341 oh = container_of0(handle, struct osd_thandle, ot_super);
343 down_read(&obj->oo_guard);
344 __osd_xattr_declare_set(env, obj, buf->lb_len, name, oh);
345 up_read(&obj->oo_guard);
351 * Set an extended attribute.
352 * This transaction must have called udmu_xattr_declare_set() first.
354 * Returns 0 on success or a negative error number on failure.
356 * No locking is done here.
358 int __osd_sa_xattr_update(const struct lu_env *env, struct osd_object *obj,
359 struct osd_thandle *oh)
361 struct osd_device *osd = osd_obj2dev(obj);
367 LASSERT(obj->oo_sa_hdl);
368 LASSERT(obj->oo_sa_xattr);
370 /* Update the SA for additions, modifications, and removals. */
371 rc = -nvlist_size(obj->oo_sa_xattr, &sa_size, NV_ENCODE_XDR);
375 dxattr = osd_zio_buf_alloc(sa_size);
379 rc = -nvlist_pack(obj->oo_sa_xattr, &dxattr, &sa_size,
380 NV_ENCODE_XDR, KM_SLEEP);
384 rc = osd_object_sa_update(obj, SA_ZPL_DXATTR(osd), dxattr, sa_size, oh);
386 osd_zio_buf_free(dxattr, sa_size);
390 int __osd_sa_xattr_set(const struct lu_env *env, struct osd_object *obj,
391 const struct lu_buf *buf, const char *name, int fl,
392 struct osd_thandle *oh)
400 rc = __osd_xattr_cache(obj);
404 LASSERT(obj->oo_sa_xattr);
405 /* Limited to 32k to keep nvpair memory allocations small */
406 if (buf->lb_len > DXATTR_MAX_ENTRY_SIZE) {
409 /* Prevent the DXATTR SA from consuming the entire SA
411 rc = -nvlist_size(obj->oo_sa_xattr, &size, NV_ENCODE_XDR);
415 if (size + buf->lb_len > DXATTR_MAX_SA_SIZE)
419 /* even in case of -EFBIG we must lookup xattr and check can we
420 * rewrite it then delete from SA */
421 rc = -nvlist_lookup_byte_array(obj->oo_sa_xattr, name, &nv_value,
424 if (fl & LU_XATTR_CREATE) {
426 } else if (too_big) {
427 rc = -nvlist_remove(obj->oo_sa_xattr, name,
428 DATA_TYPE_BYTE_ARRAY);
431 rc = __osd_sa_xattr_update(env, obj, oh);
432 return rc == 0 ? -EFBIG : rc;
434 } else if (rc == -ENOENT) {
435 if (fl & LU_XATTR_REPLACE)
443 /* Ensure xattr doesn't exist in ZAP */
444 if (obj->oo_xattr != ZFS_NO_OBJECT) {
445 struct osd_device *osd = osd_obj2dev(obj);
447 rc = -zap_lookup(osd->od_os, obj->oo_xattr,
450 rc = -dmu_object_free(osd->od_os, objid, oh->ot_tx);
452 zap_remove(osd->od_os, obj->oo_xattr,
457 rc = -nvlist_add_byte_array(obj->oo_sa_xattr, name,
458 (uchar_t *)buf->lb_buf, buf->lb_len);
462 rc = __osd_sa_xattr_update(env, obj, oh);
467 __osd_xattr_set(const struct lu_env *env, struct osd_object *obj,
468 const struct lu_buf *buf, const char *name, int fl,
469 struct osd_thandle *oh)
471 struct osd_device *osd = osd_obj2dev(obj);
472 dnode_t *xa_zap_dn = NULL;
473 dnode_t *xa_data_dn = NULL;
474 uint64_t xa_data_obj;
475 sa_handle_t *sa_hdl = NULL;
476 dmu_tx_t *tx = oh->ot_tx;
480 LASSERT(obj->oo_sa_hdl);
482 if (obj->oo_xattr == ZFS_NO_OBJECT) {
483 struct lu_attr *la = &osd_oti_get(env)->oti_la;
485 la->la_valid = LA_MODE;
486 la->la_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO;
487 rc = __osd_zap_create(env, osd, &xa_zap_dn, tx, la, 0);
491 obj->oo_xattr = xa_zap_dn->dn_object;
492 rc = osd_object_sa_update(obj, SA_ZPL_XATTR(osd),
493 &obj->oo_xattr, 8, oh);
498 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
501 if (fl & LU_XATTR_CREATE) {
506 * Entry already exists.
507 * We'll truncate the existing object.
509 rc = __osd_obj2dnode(osd->od_os, xa_data_obj, &xa_data_dn);
513 rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL,
514 SA_HDL_PRIVATE, &sa_hdl);
518 rc = -sa_lookup(sa_hdl, SA_ZPL_SIZE(osd), &size, 8);
522 rc = -dmu_free_range(osd->od_os, xa_data_dn->dn_object,
523 0, DMU_OBJECT_END, tx);
526 } else if (rc == -ENOENT) {
527 struct lu_attr *la = &osd_oti_get(env)->oti_la;
529 * Entry doesn't exist, we need to create a new one and a new
530 * object to store the value.
532 if (fl & LU_XATTR_REPLACE) {
533 /* should be ENOATTR according to the
534 * man, but that is undefined here */
539 la->la_valid = LA_MODE;
540 la->la_mode = S_IFREG | S_IRUGO | S_IWUSR;
541 rc = __osd_object_create(env, obj, &xa_data_dn, tx, la);
544 xa_data_obj = xa_data_dn->dn_object;
546 rc = -sa_handle_get(osd->od_os, xa_data_obj, NULL,
547 SA_HDL_PRIVATE, &sa_hdl);
551 rc = -zap_add(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t),
552 1, &xa_data_obj, tx);
556 /* There was an error looking up the xattr name */
560 /* Finally write the xattr value */
561 dmu_write(osd->od_os, xa_data_obj, 0, buf->lb_len, buf->lb_buf, tx);
564 rc = -sa_update(sa_hdl, SA_ZPL_SIZE(osd), &size, 8, tx);
567 sa_handle_destroy(sa_hdl);
569 if (xa_data_dn != NULL)
570 osd_dnode_rele(xa_data_dn);
571 if (xa_zap_dn != NULL)
572 osd_dnode_rele(xa_zap_dn);
577 int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
578 const struct lu_buf *buf, const char *name, int fl,
579 struct thandle *handle)
581 struct osd_object *obj = osd_dt_obj(dt);
582 struct osd_thandle *oh;
586 LASSERT(handle != NULL);
587 LASSERT(osd_invariant(obj));
589 if (!osd_obj2dev(obj)->od_posix_acl &&
590 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
591 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
594 oh = container_of0(handle, struct osd_thandle, ot_super);
596 down_write(&obj->oo_guard);
597 CDEBUG(D_INODE, "Setting xattr %s with size %d\n",
598 name, (int)buf->lb_len);
599 rc = osd_xattr_set_internal(env, obj, buf, name, fl, oh);
600 up_write(&obj->oo_guard);
606 __osd_xattr_declare_del(const struct lu_env *env, struct osd_object *obj,
607 const char *name, struct osd_thandle *oh)
609 struct osd_device *osd = osd_obj2dev(obj);
610 dmu_tx_t *tx = oh->ot_tx;
611 uint64_t xa_data_obj;
614 /* update SA_ZPL_DXATTR if xattr was in SA */
615 dmu_tx_hold_sa(tx, obj->oo_sa_hdl, 0);
617 if (obj->oo_xattr == ZFS_NO_OBJECT)
620 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, 8, 1, &xa_data_obj);
624 * We'll delete the existing object and ZAP entry.
626 dmu_tx_hold_bonus(tx, xa_data_obj);
627 dmu_tx_hold_free(tx, xa_data_obj, 0, DMU_OBJECT_END);
628 dmu_tx_hold_zap(tx, obj->oo_xattr, FALSE, (char *) name);
630 } else if (rc == -ENOENT) {
632 * Entry doesn't exist, nothing to be changed.
637 /* An error happened */
641 int osd_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
642 const char *name, struct thandle *handle)
644 struct osd_object *obj = osd_dt_obj(dt);
645 struct osd_thandle *oh;
648 LASSERT(handle != NULL);
649 LASSERT(osd_invariant(obj));
651 oh = container_of0(handle, struct osd_thandle, ot_super);
652 LASSERT(oh->ot_tx != NULL);
653 LASSERT(obj->oo_dn != NULL);
655 down_read(&obj->oo_guard);
656 if (likely(dt_object_exists(&obj->oo_dt) && !obj->oo_destroyed))
657 __osd_xattr_declare_del(env, obj, name, oh);
658 up_read(&obj->oo_guard);
663 static int __osd_sa_xattr_del(const struct lu_env *env, struct osd_object *obj,
664 const char *name, struct osd_thandle *oh)
668 rc = __osd_xattr_cache(obj);
672 rc = -nvlist_remove(obj->oo_sa_xattr, name, DATA_TYPE_BYTE_ARRAY);
674 rc = __osd_sa_xattr_update(env, obj, oh);
678 static int __osd_xattr_del(const struct lu_env *env, struct osd_object *obj,
679 const char *name, struct osd_thandle *oh)
681 struct osd_device *osd = osd_obj2dev(obj);
682 uint64_t xa_data_obj;
685 if (unlikely(!dt_object_exists(&obj->oo_dt) || obj->oo_destroyed))
688 /* try remove xattr from SA at first */
689 rc = __osd_sa_xattr_del(env, obj, name, oh);
693 if (obj->oo_xattr == ZFS_NO_OBJECT)
696 rc = -zap_lookup(osd->od_os, obj->oo_xattr, name, sizeof(uint64_t), 1,
700 } else if (rc == 0) {
703 * We'll delete the existing object and ZAP entry.
705 rc = -dmu_object_free(osd->od_os, xa_data_obj, oh->ot_tx);
709 rc = -zap_remove(osd->od_os, obj->oo_xattr, name, oh->ot_tx);
715 int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
716 const char *name, struct thandle *handle)
718 struct osd_object *obj = osd_dt_obj(dt);
719 struct osd_thandle *oh;
723 LASSERT(handle != NULL);
724 LASSERT(obj->oo_dn != NULL);
725 LASSERT(osd_invariant(obj));
726 LASSERT(dt_object_exists(dt));
727 oh = container_of0(handle, struct osd_thandle, ot_super);
728 LASSERT(oh->ot_tx != NULL);
730 if (!osd_obj2dev(obj)->od_posix_acl &&
731 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
732 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
735 down_write(&obj->oo_guard);
736 rc = __osd_xattr_del(env, obj, name, oh);
737 up_write(&obj->oo_guard);
742 void osd_declare_xattrs_destroy(const struct lu_env *env,
743 struct osd_object *obj, struct osd_thandle *oh)
745 struct osd_device *osd = osd_obj2dev(obj);
746 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
747 uint64_t oid = obj->oo_xattr, xid;
748 dmu_tx_t *tx = oh->ot_tx;
752 if (oid == ZFS_NO_OBJECT)
753 return; /* Nothing to do for SA xattrs */
755 /* Declare to free the ZAP holding xattrs */
756 dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END);
758 rc = osd_zap_cursor_init(&zc, osd->od_os, oid, 0);
762 while (zap_cursor_retrieve(zc, za) == 0) {
763 LASSERT(za->za_num_integers == 1);
764 LASSERT(za->za_integer_length == sizeof(uint64_t));
766 rc = -zap_lookup(osd->od_os, oid, za->za_name,
767 sizeof(uint64_t), 1, &xid);
769 CERROR("%s: xattr %s lookup failed: rc = %d\n",
770 osd->od_svname, za->za_name, rc);
773 dmu_tx_hold_free(tx, xid, 0, DMU_OBJECT_END);
775 zap_cursor_advance(zc);
778 osd_zap_cursor_fini(zc);
780 if (rc && tx->tx_err == 0)
784 int osd_xattrs_destroy(const struct lu_env *env,
785 struct osd_object *obj, struct osd_thandle *oh)
787 struct osd_device *osd = osd_obj2dev(obj);
788 dmu_tx_t *tx = oh->ot_tx;
789 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
794 /* The transaction must have been assigned to a transaction group. */
795 LASSERT(tx->tx_txg != 0);
797 if (obj->oo_xattr == ZFS_NO_OBJECT)
798 return 0; /* Nothing to do for SA xattrs */
800 /* Free the ZAP holding the xattrs */
801 rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0);
805 while (zap_cursor_retrieve(zc, za) == 0) {
806 LASSERT(za->za_num_integers == 1);
807 LASSERT(za->za_integer_length == sizeof(uint64_t));
809 rc = -zap_lookup(osd->od_os, obj->oo_xattr, za->za_name,
810 sizeof(uint64_t), 1, &xid);
812 CERROR("%s: lookup xattr %s failed: rc = %d\n",
813 osd->od_svname, za->za_name, rc);
815 rc = -dmu_object_free(osd->od_os, xid, tx);
817 CERROR("%s: free xattr %s failed: rc = %d\n",
818 osd->od_svname, za->za_name, rc);
820 zap_cursor_advance(zc);
822 osd_zap_cursor_fini(zc);
824 rc = -dmu_object_free(osd->od_os, obj->oo_xattr, tx);
826 CERROR("%s: free xattr %llu failed: rc = %d\n",
827 osd->od_svname, obj->oo_xattr, rc);
833 osd_sa_xattr_list(const struct lu_env *env, struct osd_object *obj,
834 const struct lu_buf *lb)
836 nvpair_t *nvp = NULL;
837 int len, counted = 0;
840 rc = __osd_xattr_cache(obj);
844 while ((nvp = nvlist_next_nvpair(obj->oo_sa_xattr, nvp)) != NULL) {
845 const char *name = nvpair_name(nvp);
847 if (!osd_obj2dev(obj)->od_posix_acl &&
848 (strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
849 strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
853 if (lb->lb_buf != NULL) {
854 if (counted + len + 1 > lb->lb_len)
857 memcpy(lb->lb_buf + counted, name, len + 1);
864 int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
865 const struct lu_buf *lb)
867 struct osd_object *obj = osd_dt_obj(dt);
868 struct osd_device *osd = osd_obj2dev(obj);
869 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
874 LASSERT(obj->oo_dn != NULL);
875 LASSERT(osd_invariant(obj));
876 LASSERT(dt_object_exists(dt));
878 down_read(&obj->oo_guard);
880 rc = osd_sa_xattr_list(env, obj, lb);
886 /* continue with dnode xattr if any */
887 if (obj->oo_xattr == ZFS_NO_OBJECT)
888 GOTO(out, rc = counted);
890 rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0);
894 while ((rc = -zap_cursor_retrieve(zc, za)) == 0) {
895 if (!osd_obj2dev(obj)->od_posix_acl &&
896 (strcmp(za->za_name, XATTR_NAME_POSIX_ACL_ACCESS) == 0 ||
897 strcmp(za->za_name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0)) {
898 zap_cursor_advance(zc);
902 rc = strlen(za->za_name);
903 if (lb->lb_buf != NULL) {
904 if (counted + rc + 1 > lb->lb_len)
905 GOTO(out_fini, rc = -ERANGE);
907 memcpy(lb->lb_buf + counted, za->za_name, rc + 1);
911 zap_cursor_advance(zc);
913 if (rc == -ENOENT) /* no more kes in the index */
915 else if (unlikely(rc < 0))
920 osd_zap_cursor_fini(zc);
922 up_read(&obj->oo_guard);