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, 2014, 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_object.c
38 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
39 * Author: Mike Pershin <tappro@whamcloud.com>
40 * Author: Johann Lombardi <johann@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 char *osd_obj_tag = "osd_object";
71 static struct dt_object_operations osd_obj_ops;
72 static struct lu_object_operations osd_lu_obj_ops;
73 extern struct dt_body_operations osd_body_ops;
74 static struct dt_object_operations osd_obj_otable_it_ops;
76 extern struct kmem_cache *osd_object_kmem;
79 osd_object_sa_fini(struct osd_object *obj)
82 sa_handle_destroy(obj->oo_sa_hdl);
83 obj->oo_sa_hdl = NULL;
88 osd_object_sa_init(struct osd_object *obj, struct osd_device *o)
92 LASSERT(obj->oo_sa_hdl == NULL);
93 LASSERT(obj->oo_db != NULL);
95 rc = -sa_handle_get(o->od_os, obj->oo_db->db_object, obj,
96 SA_HDL_PRIVATE, &obj->oo_sa_hdl);
100 /* Cache the xattr object id, valid for the life of the object */
101 rc = -sa_lookup(obj->oo_sa_hdl, SA_ZPL_XATTR(o), &obj->oo_xattr, 8);
103 obj->oo_xattr = ZFS_NO_OBJECT;
106 osd_object_sa_fini(obj);
113 * Add object to list of dirty objects in tx handle.
116 osd_object_sa_dirty_add(struct osd_object *obj, struct osd_thandle *oh)
118 if (!list_empty(&obj->oo_sa_linkage))
121 down(&oh->ot_sa_lock);
122 write_lock(&obj->oo_attr_lock);
123 if (likely(list_empty(&obj->oo_sa_linkage)))
124 list_add(&obj->oo_sa_linkage, &oh->ot_sa_list);
125 write_unlock(&obj->oo_attr_lock);
130 * Release spill block dbuf hold for all dirty SAs.
132 void osd_object_sa_dirty_rele(struct osd_thandle *oh)
134 struct osd_object *obj;
136 down(&oh->ot_sa_lock);
137 while (!list_empty(&oh->ot_sa_list)) {
138 obj = list_entry(oh->ot_sa_list.next,
139 struct osd_object, oo_sa_linkage);
140 sa_spill_rele(obj->oo_sa_hdl);
141 write_lock(&obj->oo_attr_lock);
142 list_del_init(&obj->oo_sa_linkage);
143 write_unlock(&obj->oo_attr_lock);
149 * Update the SA and add the object to the dirty list.
151 int osd_object_sa_update(struct osd_object *obj, sa_attr_type_t type,
152 void *buf, uint32_t buflen, struct osd_thandle *oh)
156 LASSERT(obj->oo_sa_hdl != NULL);
157 LASSERT(oh->ot_tx != NULL);
159 rc = -sa_update(obj->oo_sa_hdl, type, buf, buflen, oh->ot_tx);
160 osd_object_sa_dirty_add(obj, oh);
166 * Bulk update the SA and add the object to the dirty list.
169 osd_object_sa_bulk_update(struct osd_object *obj, sa_bulk_attr_t *attrs,
170 int count, struct osd_thandle *oh)
174 LASSERT(obj->oo_sa_hdl != NULL);
175 LASSERT(oh->ot_tx != NULL);
177 rc = -sa_bulk_update(obj->oo_sa_hdl, attrs, count, oh->ot_tx);
178 osd_object_sa_dirty_add(obj, oh);
184 * Retrieve the attributes of a DMU object
186 int __osd_object_attr_get(const struct lu_env *env, struct osd_device *o,
187 struct osd_object *obj, struct lu_attr *la)
189 struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
191 sa_bulk_attr_t *bulk;
196 LASSERT(obj->oo_db != NULL);
198 rc = -sa_handle_get(o->od_os, obj->oo_db->db_object, NULL,
199 SA_HDL_PRIVATE, &sa_hdl);
203 OBD_ALLOC(bulk, sizeof(sa_bulk_attr_t) * 9);
205 GOTO(out_sa, rc = -ENOMEM);
207 la->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE | LA_TYPE |
208 LA_SIZE | LA_UID | LA_GID | LA_FLAGS | LA_NLINK;
210 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(o), NULL, osa->atime, 16);
211 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(o), NULL, osa->mtime, 16);
212 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(o), NULL, osa->ctime, 16);
213 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(o), NULL, &osa->mode, 8);
214 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_SIZE(o), NULL, &osa->size, 8);
215 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(o), NULL, &osa->nlink, 8);
216 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_UID(o), NULL, &osa->uid, 8);
217 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_GID(o), NULL, &osa->gid, 8);
218 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(o), NULL, &osa->flags, 8);
220 rc = -sa_bulk_lookup(sa_hdl, bulk, cnt);
224 la->la_atime = osa->atime[0];
225 la->la_mtime = osa->mtime[0];
226 la->la_ctime = osa->ctime[0];
227 la->la_mode = osa->mode;
228 la->la_uid = osa->uid;
229 la->la_gid = osa->gid;
230 la->la_nlink = osa->nlink;
231 la->la_flags = attrs_zfs2fs(osa->flags);
232 la->la_size = osa->size;
234 if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode)) {
235 rc = -sa_lookup(sa_hdl, SA_ZPL_RDEV(o), &osa->rdev, 8);
238 la->la_rdev = osa->rdev;
239 la->la_valid |= LA_RDEV;
242 OBD_FREE(bulk, sizeof(sa_bulk_attr_t) * 9);
244 sa_handle_destroy(sa_hdl);
249 int __osd_obj2dbuf(const struct lu_env *env, objset_t *os,
250 uint64_t oid, dmu_buf_t **dbp)
252 dmu_object_info_t *doi = &osd_oti_get(env)->oti_doi;
255 rc = -sa_buf_hold(os, oid, osd_obj_tag, dbp);
259 dmu_object_info_from_db(*dbp, doi);
260 if (unlikely (oid != DMU_USERUSED_OBJECT &&
261 oid != DMU_GROUPUSED_OBJECT && doi->doi_bonus_type != DMU_OT_SA)) {
262 sa_buf_rele(*dbp, osd_obj_tag);
268 LASSERT((*dbp)->db_object == oid);
269 LASSERT((*dbp)->db_offset == -1);
270 LASSERT((*dbp)->db_data != NULL);
276 * Concurrency: no concurrent access is possible that early in object
279 struct lu_object *osd_object_alloc(const struct lu_env *env,
280 const struct lu_object_header *hdr,
283 struct osd_object *mo;
285 OBD_SLAB_ALLOC_PTR_GFP(mo, osd_object_kmem, GFP_NOFS);
289 l = &mo->oo_dt.do_lu;
290 dt_object_init(&mo->oo_dt, NULL, d);
291 mo->oo_dt.do_ops = &osd_obj_ops;
292 l->lo_ops = &osd_lu_obj_ops;
293 INIT_LIST_HEAD(&mo->oo_sa_linkage);
294 init_rwsem(&mo->oo_sem);
295 sema_init(&mo->oo_guard, 1);
296 rwlock_init(&mo->oo_attr_lock);
304 * Concurrency: shouldn't matter.
306 int osd_object_init0(const struct lu_env *env, struct osd_object *obj)
308 struct osd_device *osd = osd_obj2dev(obj);
309 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
313 if (obj->oo_db == NULL)
318 rc = osd_object_sa_init(obj, osd);
322 /* cache attrs in object */
323 rc = __osd_object_attr_get(env, osd, obj, &obj->oo_attr);
327 if (likely(!fid_is_acct(fid)))
328 /* no body operations for accounting objects */
329 obj->oo_dt.do_body_ops = &osd_body_ops;
332 * initialize object before marking it existing
334 obj->oo_dt.do_lu.lo_header->loh_attr |= obj->oo_attr.la_mode & S_IFMT;
337 obj->oo_dt.do_lu.lo_header->loh_attr |= LOHA_EXISTS;
342 static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
344 struct osd_thread_info *info = osd_oti_get(env);
347 struct lustre_mdt_attrs *lma;
350 CLASSERT(sizeof(info->oti_buf) >= sizeof(*lma));
351 lma = (struct lustre_mdt_attrs *)info->oti_buf;
353 buf.lb_len = sizeof(info->oti_buf);
355 rc = osd_xattr_get(env, &obj->oo_dt, &buf, XATTR_NAME_LMA);
358 lustre_lma_swab(lma);
359 if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
360 CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT))) {
361 CWARN("%s: unsupported incompat LMA feature(s) %#x for "
362 "fid = "DFID"\n", osd_obj2dev(obj)->od_svname,
363 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
364 PFID(lu_object_fid(&obj->oo_dt.do_lu)));
367 } else if (rc == -ENODATA) {
368 /* haven't initialize LMA xattr */
376 * Concurrency: no concurrent access is possible that early in object
379 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
380 const struct lu_object_conf *conf)
382 struct osd_object *obj = osd_obj(l);
383 struct osd_device *osd = osd_obj2dev(obj);
388 LASSERT(osd_invariant(obj));
390 if (fid_is_otable_it(&l->lo_header->loh_fid)) {
391 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
392 l->lo_header->loh_attr |= LOHA_EXISTS;
396 rc = osd_fid_lookup(env, osd, lu_object_fid(l), &oid);
398 LASSERT(obj->oo_db == NULL);
399 rc = __osd_obj2dbuf(env, osd->od_os, oid, &obj->oo_db);
401 CERROR("%s: lookup "DFID"/"LPX64" failed: rc = %d\n",
402 osd->od_svname, PFID(lu_object_fid(l)), oid, rc);
406 rc = osd_object_init0(env, obj);
410 rc = osd_check_lma(env, obj);
413 } else if (rc == -ENOENT) {
416 LASSERT(osd_invariant(obj));
422 * Concurrency: no concurrent access is possible that late in object
425 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
427 struct osd_object *obj = osd_obj(l);
429 LASSERT(osd_invariant(obj));
431 dt_object_fini(&obj->oo_dt);
432 OBD_SLAB_FREE_PTR(obj, osd_object_kmem);
435 static void __osd_declare_object_destroy(const struct lu_env *env,
436 struct osd_object *obj,
437 struct osd_thandle *oh)
439 struct osd_device *osd = osd_obj2dev(obj);
440 dmu_buf_t *db = obj->oo_db;
441 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
442 uint64_t oid = db->db_object, xid;
443 dmu_tx_t *tx = oh->ot_tx;
447 dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END);
449 /* zap holding xattrs */
450 if (obj->oo_xattr != ZFS_NO_OBJECT) {
453 dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END);
455 rc = osd_zap_cursor_init(&zc, osd->od_os, oid, 0);
459 while ((rc = -zap_cursor_retrieve(zc, za)) == 0) {
460 BUG_ON(za->za_integer_length != sizeof(uint64_t));
461 BUG_ON(za->za_num_integers != 1);
463 rc = -zap_lookup(osd->od_os, obj->oo_xattr, za->za_name,
464 sizeof(uint64_t), 1, &xid);
466 CERROR("%s: xattr lookup failed: rc = %d\n",
470 dmu_tx_hold_free(tx, xid, 0, DMU_OBJECT_END);
472 zap_cursor_advance(zc);
477 osd_zap_cursor_fini(zc);
480 if (rc && tx->tx_err == 0)
484 static int osd_declare_object_destroy(const struct lu_env *env,
485 struct dt_object *dt,
488 char *buf = osd_oti_get(env)->oti_str;
489 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
490 struct osd_object *obj = osd_dt_obj(dt);
491 struct osd_device *osd = osd_obj2dev(obj);
492 struct osd_thandle *oh;
498 LASSERT(dt_object_exists(dt));
500 oh = container_of0(th, struct osd_thandle, ot_super);
501 LASSERT(oh->ot_tx != NULL);
503 /* declare that we'll destroy the object */
504 __osd_declare_object_destroy(env, obj, oh);
506 /* declare that we'll remove object from fid-dnode mapping */
507 zapid = osd_get_name_n_idx(env, osd, fid, buf);
508 dmu_tx_hold_bonus(oh->ot_tx, zapid);
509 dmu_tx_hold_zap(oh->ot_tx, zapid, 0, buf);
511 /* declare that we'll remove object from inode accounting ZAPs */
512 dmu_tx_hold_bonus(oh->ot_tx, osd->od_iusr_oid);
513 dmu_tx_hold_zap(oh->ot_tx, osd->od_iusr_oid, 0, buf);
514 dmu_tx_hold_bonus(oh->ot_tx, osd->od_igrp_oid);
515 dmu_tx_hold_zap(oh->ot_tx, osd->od_igrp_oid, 0, buf);
518 rc = osd_declare_quota(env, osd, obj->oo_attr.la_uid,
519 obj->oo_attr.la_gid, -1, oh, false, NULL, false);
523 /* data to be truncated */
524 rc = osd_declare_quota(env, osd, obj->oo_attr.la_uid,
525 obj->oo_attr.la_gid, 0, oh, true, NULL, false);
530 * Delete a DMU object
532 * The transaction passed to this routine must have
533 * dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END) called
534 * and then assigned to a transaction group.
536 * This will release db and set it to NULL to prevent further dbuf releases.
538 static int __osd_object_destroy(const struct lu_env *env,
539 struct osd_object *obj,
540 dmu_tx_t *tx, void *tag)
542 struct osd_device *osd = osd_obj2dev(obj);
544 zap_attribute_t *za = &osd_oti_get(env)->oti_za;
548 /* Assert that the transaction has been assigned to a
549 transaction group. */
550 LASSERT(tx->tx_txg != 0);
552 /* zap holding xattrs */
553 if (obj->oo_xattr != ZFS_NO_OBJECT) {
554 rc = osd_zap_cursor_init(&zc, osd->od_os, obj->oo_xattr, 0);
557 while ((rc = -zap_cursor_retrieve(zc, za)) == 0) {
558 BUG_ON(za->za_integer_length != sizeof(uint64_t));
559 BUG_ON(za->za_num_integers != 1);
561 rc = -zap_lookup(osd->od_os, obj->oo_xattr, za->za_name,
562 sizeof(uint64_t), 1, &xid);
564 CERROR("%s: lookup xattr %s failed: rc = %d\n",
565 osd->od_svname, za->za_name, rc);
568 rc = -dmu_object_free(osd->od_os, xid, tx);
570 CERROR("%s: fetch xattr %s failed: rc = %d\n",
571 osd->od_svname, za->za_name, rc);
572 zap_cursor_advance(zc);
574 osd_zap_cursor_fini(zc);
576 rc = -dmu_object_free(osd->od_os, obj->oo_xattr, tx);
578 CERROR("%s: freeing xattr failed: rc = %d\n",
582 return -dmu_object_free(osd->od_os, obj->oo_db->db_object, tx);
585 static int osd_object_destroy(const struct lu_env *env,
586 struct dt_object *dt,
589 char *buf = osd_oti_get(env)->oti_str;
590 struct osd_object *obj = osd_dt_obj(dt);
591 struct osd_device *osd = osd_obj2dev(obj);
592 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
593 struct osd_thandle *oh;
598 LASSERT(obj->oo_db != NULL);
599 LASSERT(dt_object_exists(dt));
600 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
602 oh = container_of0(th, struct osd_thandle, ot_super);
604 LASSERT(oh->ot_tx != NULL);
606 zapid = osd_get_name_n_idx(env, osd, fid, buf);
608 /* remove obj ref from index dir (it depends) */
609 rc = -zap_remove(osd->od_os, zapid, buf, oh->ot_tx);
611 CERROR("%s: zap_remove() failed: rc = %d\n",
616 /* Remove object from inode accounting. It is not fatal for the destroy
617 * operation if something goes wrong while updating accounting, but we
618 * still log an error message to notify the administrator */
619 rc = -zap_increment_int(osd->od_os, osd->od_iusr_oid,
620 obj->oo_attr.la_uid, -1, oh->ot_tx);
622 CERROR("%s: failed to remove "DFID" from accounting ZAP for usr"
623 " %d: rc = %d\n", osd->od_svname, PFID(fid),
624 obj->oo_attr.la_uid, rc);
625 rc = -zap_increment_int(osd->od_os, osd->od_igrp_oid,
626 obj->oo_attr.la_gid, -1, oh->ot_tx);
628 CERROR("%s: failed to remove "DFID" from accounting ZAP for grp"
629 " %d: rc = %d\n", osd->od_svname, PFID(fid),
630 obj->oo_attr.la_gid, rc);
633 rc = __osd_object_destroy(env, obj, oh->ot_tx, osd_obj_tag);
635 CERROR("%s: __osd_object_destroy() failed: rc = %d\n",
641 /* not needed in the cache anymore */
642 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
647 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
649 struct osd_object *obj = osd_obj(l);
651 if (obj->oo_db != NULL) {
652 osd_object_sa_fini(obj);
653 if (obj->oo_sa_xattr) {
654 nvlist_free(obj->oo_sa_xattr);
655 obj->oo_sa_xattr = NULL;
657 sa_buf_rele(obj->oo_db, osd_obj_tag);
658 list_del(&obj->oo_sa_linkage);
664 * Concurrency: ->loo_object_release() is called under site spin-lock.
666 static void osd_object_release(const struct lu_env *env,
672 * Concurrency: shouldn't matter.
674 static int osd_object_print(const struct lu_env *env, void *cookie,
675 lu_printer_t p, const struct lu_object *l)
677 struct osd_object *o = osd_obj(l);
679 return (*p)(env, cookie, LUSTRE_OSD_ZFS_NAME"-object@%p", o);
682 static void osd_object_read_lock(const struct lu_env *env,
683 struct dt_object *dt, unsigned role)
685 struct osd_object *obj = osd_dt_obj(dt);
687 LASSERT(osd_invariant(obj));
689 down_read(&obj->oo_sem);
692 static void osd_object_write_lock(const struct lu_env *env,
693 struct dt_object *dt, unsigned role)
695 struct osd_object *obj = osd_dt_obj(dt);
697 LASSERT(osd_invariant(obj));
699 down_write(&obj->oo_sem);
702 static void osd_object_read_unlock(const struct lu_env *env,
703 struct dt_object *dt)
705 struct osd_object *obj = osd_dt_obj(dt);
707 LASSERT(osd_invariant(obj));
708 up_read(&obj->oo_sem);
711 static void osd_object_write_unlock(const struct lu_env *env,
712 struct dt_object *dt)
714 struct osd_object *obj = osd_dt_obj(dt);
716 LASSERT(osd_invariant(obj));
717 up_write(&obj->oo_sem);
720 static int osd_object_write_locked(const struct lu_env *env,
721 struct dt_object *dt)
723 struct osd_object *obj = osd_dt_obj(dt);
726 LASSERT(osd_invariant(obj));
728 if (down_write_trylock(&obj->oo_sem)) {
730 up_write(&obj->oo_sem);
735 static int osd_attr_get(const struct lu_env *env,
736 struct dt_object *dt,
737 struct lu_attr *attr)
739 struct osd_object *obj = osd_dt_obj(dt);
743 LASSERT(dt_object_exists(dt));
744 LASSERT(osd_invariant(obj));
747 read_lock(&obj->oo_attr_lock);
748 *attr = obj->oo_attr;
749 read_unlock(&obj->oo_attr_lock);
751 /* with ZFS_DEBUG zrl_add_debug() called by DB_DNODE_ENTER()
752 * from within sa_object_size() can block on a mutex, so
753 * we can't call sa_object_size() holding rwlock */
754 sa_object_size(obj->oo_sa_hdl, &blksize, &blocks);
755 /* we do not control size of indices, so always calculate
756 * it from number of blocks reported by DMU */
757 if (S_ISDIR(attr->la_mode))
758 attr->la_size = 512 * blocks;
759 /* Block size may be not set; suggest maximal I/O transfers. */
761 blksize = 1ULL << SPA_MAXBLOCKSHIFT;
763 attr->la_blksize = blksize;
764 attr->la_blocks = blocks;
765 attr->la_valid |= LA_BLOCKS | LA_BLKSIZE;
770 /* Simple wrapper on top of qsd API which implement quota transfer for osd
771 * setattr needs. As a reminder, only the root user can change ownership of
772 * a file, that's why EDQUOT & EINPROGRESS errors are discarded */
773 static inline int qsd_transfer(const struct lu_env *env,
774 struct qsd_instance *qsd,
775 struct lquota_trans *trans, int qtype,
776 __u64 orig_id, __u64 new_id, __u64 bspace,
777 struct lquota_id_info *qi)
781 if (unlikely(qsd == NULL))
784 LASSERT(qtype >= 0 && qtype < MAXQUOTAS);
785 qi->lqi_type = qtype;
787 /* inode accounting */
788 qi->lqi_is_blk = false;
790 /* one more inode for the new owner ... */
791 qi->lqi_id.qid_uid = new_id;
793 rc = qsd_op_begin(env, qsd, trans, qi, NULL);
794 if (rc == -EDQUOT || rc == -EINPROGRESS)
799 /* and one less inode for the current id */
800 qi->lqi_id.qid_uid = orig_id;;
802 /* can't get EDQUOT when reducing usage */
803 rc = qsd_op_begin(env, qsd, trans, qi, NULL);
804 if (rc == -EINPROGRESS)
809 /* block accounting */
810 qi->lqi_is_blk = true;
812 /* more blocks for the new owner ... */
813 qi->lqi_id.qid_uid = new_id;
814 qi->lqi_space = bspace;
815 rc = qsd_op_begin(env, qsd, trans, qi, NULL);
816 if (rc == -EDQUOT || rc == -EINPROGRESS)
821 /* and finally less blocks for the current owner */
822 qi->lqi_id.qid_uid = orig_id;
823 qi->lqi_space = -bspace;
824 rc = qsd_op_begin(env, qsd, trans, qi, NULL);
825 /* can't get EDQUOT when reducing usage */
826 if (rc == -EINPROGRESS)
831 static int osd_declare_attr_set(const struct lu_env *env,
832 struct dt_object *dt,
833 const struct lu_attr *attr,
834 struct thandle *handle)
836 struct osd_thread_info *info = osd_oti_get(env);
837 char *buf = osd_oti_get(env)->oti_str;
838 struct osd_object *obj = osd_dt_obj(dt);
839 struct osd_device *osd = osd_obj2dev(obj);
840 struct osd_thandle *oh;
846 if (!dt_object_exists(dt)) {
847 /* XXX: sanity check that object creation is declared */
851 LASSERT(handle != NULL);
852 LASSERT(osd_invariant(obj));
854 oh = container_of0(handle, struct osd_thandle, ot_super);
856 LASSERT(obj->oo_sa_hdl != NULL);
857 LASSERT(oh->ot_tx != NULL);
858 dmu_tx_hold_sa(oh->ot_tx, obj->oo_sa_hdl, 0);
859 if (oh->ot_tx->tx_err != 0)
860 RETURN(-oh->ot_tx->tx_err);
862 sa_object_size(obj->oo_sa_hdl, &blksize, &bspace);
863 bspace = toqb(bspace * blksize);
865 if (attr && attr->la_valid & LA_UID) {
866 /* account for user inode tracking ZAP update */
867 dmu_tx_hold_bonus(oh->ot_tx, osd->od_iusr_oid);
868 dmu_tx_hold_zap(oh->ot_tx, osd->od_iusr_oid, TRUE, buf);
870 /* quota enforcement for user */
871 if (attr->la_uid != obj->oo_attr.la_uid) {
872 rc = qsd_transfer(env, osd->od_quota_slave,
873 &oh->ot_quota_trans, USRQUOTA,
874 obj->oo_attr.la_uid, attr->la_uid,
875 bspace, &info->oti_qi);
880 if (attr && attr->la_valid & LA_GID) {
881 /* account for user inode tracking ZAP update */
882 dmu_tx_hold_bonus(oh->ot_tx, osd->od_igrp_oid);
883 dmu_tx_hold_zap(oh->ot_tx, osd->od_igrp_oid, TRUE, buf);
885 /* quota enforcement for group */
886 if (attr->la_gid != obj->oo_attr.la_gid) {
887 rc = qsd_transfer(env, osd->od_quota_slave,
888 &oh->ot_quota_trans, GRPQUOTA,
889 obj->oo_attr.la_gid, attr->la_gid,
890 bspace, &info->oti_qi);
900 * Set the attributes of an object
902 * The transaction passed to this routine must have
903 * dmu_tx_hold_bonus(tx, oid) called and then assigned
904 * to a transaction group.
906 static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
907 const struct lu_attr *la, struct thandle *handle)
909 struct osd_object *obj = osd_dt_obj(dt);
910 struct osd_device *osd = osd_obj2dev(obj);
911 struct osd_thandle *oh;
912 struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
913 sa_bulk_attr_t *bulk;
914 __u64 valid = la->la_valid;
919 LASSERT(handle != NULL);
920 LASSERT(dt_object_exists(dt));
921 LASSERT(osd_invariant(obj));
922 LASSERT(obj->oo_sa_hdl);
924 oh = container_of0(handle, struct osd_thandle, ot_super);
925 /* Assert that the transaction has been assigned to a
926 transaction group. */
927 LASSERT(oh->ot_tx->tx_txg != 0);
929 /* Only allow set size for regular file */
930 if (!S_ISREG(dt->do_lu.lo_header->loh_attr))
931 valid &= ~(LA_SIZE | LA_BLOCKS);
936 OBD_ALLOC(bulk, sizeof(sa_bulk_attr_t) * 10);
940 /* do both accounting updates outside oo_attr_lock below */
941 if ((valid & LA_UID) && (la->la_uid != obj->oo_attr.la_uid)) {
942 /* Update user accounting. Failure isn't fatal, but we still
943 * log an error message */
944 rc = -zap_increment_int(osd->od_os, osd->od_iusr_oid,
945 la->la_uid, 1, oh->ot_tx);
947 CERROR("%s: failed to update accounting ZAP for user "
948 "%d (%d)\n", osd->od_svname, la->la_uid, rc);
949 rc = -zap_increment_int(osd->od_os, osd->od_iusr_oid,
950 obj->oo_attr.la_uid, -1, oh->ot_tx);
952 CERROR("%s: failed to update accounting ZAP for user "
953 "%d (%d)\n", osd->od_svname,
954 obj->oo_attr.la_uid, rc);
956 if ((valid & LA_GID) && (la->la_gid != obj->oo_attr.la_gid)) {
957 /* Update group accounting. Failure isn't fatal, but we still
958 * log an error message */
959 rc = -zap_increment_int(osd->od_os, osd->od_igrp_oid,
960 la->la_gid, 1, oh->ot_tx);
962 CERROR("%s: failed to update accounting ZAP for user "
963 "%d (%d)\n", osd->od_svname, la->la_gid, rc);
964 rc = -zap_increment_int(osd->od_os, osd->od_igrp_oid,
965 obj->oo_attr.la_gid, -1, oh->ot_tx);
967 CERROR("%s: failed to update accounting ZAP for user "
968 "%d (%d)\n", osd->od_svname,
969 obj->oo_attr.la_gid, rc);
972 write_lock(&obj->oo_attr_lock);
974 if (valid & LA_ATIME) {
975 osa->atime[0] = obj->oo_attr.la_atime = la->la_atime;
976 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(osd), NULL,
979 if (valid & LA_MTIME) {
980 osa->mtime[0] = obj->oo_attr.la_mtime = la->la_mtime;
981 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(osd), NULL,
984 if (valid & LA_CTIME) {
985 osa->ctime[0] = obj->oo_attr.la_ctime = la->la_ctime;
986 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(osd), NULL,
989 if (valid & LA_MODE) {
990 /* mode is stored along with type, so read it first */
991 obj->oo_attr.la_mode = (obj->oo_attr.la_mode & S_IFMT) |
992 (la->la_mode & ~S_IFMT);
993 osa->mode = obj->oo_attr.la_mode;
994 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(osd), NULL,
997 if (valid & LA_SIZE) {
998 osa->size = obj->oo_attr.la_size = la->la_size;
999 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_SIZE(osd), NULL,
1002 if (valid & LA_NLINK) {
1003 osa->nlink = obj->oo_attr.la_nlink = la->la_nlink;
1004 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(osd), NULL,
1007 if (valid & LA_RDEV) {
1008 osa->rdev = obj->oo_attr.la_rdev = la->la_rdev;
1009 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_RDEV(osd), NULL,
1012 if (valid & LA_FLAGS) {
1013 osa->flags = attrs_fs2zfs(la->la_flags);
1014 /* many flags are not supported by zfs, so ensure a good cached
1016 obj->oo_attr.la_flags = attrs_zfs2fs(osa->flags);
1017 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(osd), NULL,
1020 if (valid & LA_UID) {
1021 osa->uid = obj->oo_attr.la_uid = la->la_uid;
1022 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_UID(osd), NULL,
1025 if (valid & LA_GID) {
1026 osa->gid = obj->oo_attr.la_gid = la->la_gid;
1027 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_GID(osd), NULL,
1030 obj->oo_attr.la_valid |= valid;
1031 write_unlock(&obj->oo_attr_lock);
1033 rc = osd_object_sa_bulk_update(obj, bulk, cnt, oh);
1035 OBD_FREE(bulk, sizeof(sa_bulk_attr_t) * 10);
1042 * XXX temporary solution.
1045 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1046 struct dt_object *parent, struct dt_object *child,
1051 ah->dah_parent = parent;
1052 ah->dah_mode = child_mode;
1055 static int osd_declare_object_create(const struct lu_env *env,
1056 struct dt_object *dt,
1057 struct lu_attr *attr,
1058 struct dt_allocation_hint *hint,
1059 struct dt_object_format *dof,
1060 struct thandle *handle)
1062 char *buf = osd_oti_get(env)->oti_str;
1063 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1064 struct osd_object *obj = osd_dt_obj(dt);
1065 struct osd_device *osd = osd_obj2dev(obj);
1066 struct osd_thandle *oh;
1073 switch (dof->dof_type) {
1077 if (obj->oo_dt.do_body_ops == NULL)
1078 obj->oo_dt.do_body_ops = &osd_body_ops;
1084 LASSERT(handle != NULL);
1085 oh = container_of0(handle, struct osd_thandle, ot_super);
1086 LASSERT(oh->ot_tx != NULL);
1088 switch (dof->dof_type) {
1090 dt->do_index_ops = &osd_dir_ops;
1092 /* for zap create */
1093 dmu_tx_hold_zap(oh->ot_tx, DMU_NEW_OBJECT, 1, NULL);
1098 /* first, we'll create new object */
1099 dmu_tx_hold_bonus(oh->ot_tx, DMU_NEW_OBJECT);
1107 /* and we'll add it to some mapping */
1108 zapid = osd_get_name_n_idx(env, osd, fid, buf);
1109 dmu_tx_hold_bonus(oh->ot_tx, zapid);
1110 dmu_tx_hold_zap(oh->ot_tx, zapid, TRUE, buf);
1112 /* we will also update inode accounting ZAPs */
1113 dmu_tx_hold_bonus(oh->ot_tx, osd->od_iusr_oid);
1114 dmu_tx_hold_zap(oh->ot_tx, osd->od_iusr_oid, TRUE, buf);
1115 dmu_tx_hold_bonus(oh->ot_tx, osd->od_igrp_oid);
1116 dmu_tx_hold_zap(oh->ot_tx, osd->od_igrp_oid, TRUE, buf);
1118 dmu_tx_hold_sa_create(oh->ot_tx, ZFS_SA_BASE_ATTR_SIZE);
1120 __osd_xattr_declare_set(env, obj, sizeof(struct lustre_mdt_attrs),
1121 XATTR_NAME_LMA, oh);
1123 rc = osd_declare_quota(env, osd, attr->la_uid, attr->la_gid, 1, oh,
1124 false, NULL, false);
1128 int __osd_attr_init(const struct lu_env *env, struct osd_device *osd,
1129 uint64_t oid, dmu_tx_t *tx, struct lu_attr *la,
1132 sa_bulk_attr_t *bulk;
1133 sa_handle_t *sa_hdl;
1134 struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
1142 gen = dmu_tx_get_txg(tx);
1144 ZFS_TIME_ENCODE(&now, crtime);
1146 osa->atime[0] = la->la_atime;
1147 osa->ctime[0] = la->la_ctime;
1148 osa->mtime[0] = la->la_mtime;
1149 osa->mode = la->la_mode;
1150 osa->uid = la->la_uid;
1151 osa->gid = la->la_gid;
1152 osa->rdev = la->la_rdev;
1153 osa->nlink = la->la_nlink;
1154 osa->flags = attrs_fs2zfs(la->la_flags);
1155 osa->size = la->la_size;
1157 /* Now add in all of the "SA" attributes */
1158 rc = -sa_handle_get(osd->od_os, oid, NULL, SA_HDL_PRIVATE, &sa_hdl);
1162 OBD_ALLOC(bulk, sizeof(sa_bulk_attr_t) * 13);
1168 * we need to create all SA below upon object create.
1170 * XXX The attribute order matters since the accounting callback relies
1171 * on static offsets (i.e. SA_*_OFFSET, see zfs_space_delta_cb()) to
1172 * look up the UID/GID attributes. Moreover, the callback does not seem
1173 * to support the spill block.
1174 * We define attributes in the same order as SA_*_OFFSET in order to
1175 * work around the problem. See ORI-610.
1178 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(osd), NULL, &osa->mode, 8);
1179 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_SIZE(osd), NULL, &osa->size, 8);
1180 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_GEN(osd), NULL, &gen, 8);
1181 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_UID(osd), NULL, &osa->uid, 8);
1182 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_GID(osd), NULL, &osa->gid, 8);
1183 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_PARENT(osd), NULL, &parent, 8);
1184 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(osd), NULL, &osa->flags, 8);
1185 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(osd), NULL, osa->atime, 16);
1186 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(osd), NULL, osa->mtime, 16);
1187 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(osd), NULL, osa->ctime, 16);
1188 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CRTIME(osd), NULL, crtime, 16);
1189 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(osd), NULL, &osa->nlink, 8);
1190 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_RDEV(osd), NULL, &osa->rdev, 8);
1192 rc = -sa_replace_all_by_template(sa_hdl, bulk, cnt, tx);
1194 OBD_FREE(bulk, sizeof(sa_bulk_attr_t) * 13);
1196 sa_handle_destroy(sa_hdl);
1201 * The transaction passed to this routine must have
1202 * dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT) called and then assigned
1203 * to a transaction group.
1205 int __osd_object_create(const struct lu_env *env, struct osd_object *obj,
1206 dmu_buf_t **dbp, dmu_tx_t *tx, struct lu_attr *la,
1211 struct osd_device *osd = osd_obj2dev(obj);
1212 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
1213 dmu_object_type_t type = DMU_OT_PLAIN_FILE_CONTENTS;
1215 /* Assert that the transaction has been assigned to a
1216 transaction group. */
1217 LASSERT(tx->tx_txg != 0);
1219 /* Use DMU_OTN_UINT8_METADATA for local objects so their data blocks
1220 * would get an additional ditto copy */
1221 if (unlikely(S_ISREG(la->la_mode) &&
1222 fid_seq_is_local_file(fid_seq(fid))))
1223 type = DMU_OTN_UINT8_METADATA;
1225 /* Create a new DMU object. */
1226 oid = dmu_object_alloc(osd->od_os, type, 0,
1227 DMU_OT_SA, DN_MAX_BONUSLEN, tx);
1228 rc = -sa_buf_hold(osd->od_os, oid, osd_obj_tag, dbp);
1229 LASSERTF(rc == 0, "sa_buf_hold "LPU64" failed: %d\n", oid, rc);
1231 LASSERT(la->la_valid & LA_MODE);
1235 rc = __osd_attr_init(env, osd, oid, tx, la, parent);
1237 sa_buf_rele(*dbp, osd_obj_tag);
1239 dmu_object_free(osd->od_os, oid, tx);
1247 * The transaction passed to this routine must have
1248 * dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, ...) called and then assigned
1249 * to a transaction group.
1251 * Using ZAP_FLAG_HASH64 will force the ZAP to always be a FAT ZAP.
1252 * This is fine for directories today, because storing the FID in the dirent
1253 * will also require a FAT ZAP. If there is a new type of micro ZAP created
1254 * then we might need to re-evaluate the use of this flag and instead do
1255 * a conversion from the different internal ZAP hash formats being used. */
1256 int __osd_zap_create(const struct lu_env *env, struct osd_device *osd,
1257 dmu_buf_t **zap_dbp, dmu_tx_t *tx,
1258 struct lu_attr *la, uint64_t parent, zap_flags_t flags)
1263 /* Assert that the transaction has been assigned to a
1264 transaction group. */
1265 LASSERT(tx->tx_txg != 0);
1267 oid = zap_create_flags(osd->od_os, 0, flags | ZAP_FLAG_HASH64,
1268 DMU_OT_DIRECTORY_CONTENTS,
1269 14, /* == ZFS fzap_default_block_shift */
1270 DN_MAX_INDBLKSHIFT, /* indirect block shift */
1271 DMU_OT_SA, DN_MAX_BONUSLEN, tx);
1273 rc = -sa_buf_hold(osd->od_os, oid, osd_obj_tag, zap_dbp);
1277 LASSERT(la->la_valid & LA_MODE);
1281 return __osd_attr_init(env, osd, oid, tx, la, parent);
1284 static dmu_buf_t *osd_mkidx(const struct lu_env *env, struct osd_object *obj,
1285 struct lu_attr *la, uint64_t parent,
1286 struct osd_thandle *oh)
1291 /* Index file should be created as regular file in order not to confuse
1292 * ZPL which could interpret them as directory.
1293 * We set ZAP_FLAG_UINT64_KEY to let ZFS know than we are going to use
1295 LASSERT(S_ISREG(la->la_mode));
1296 rc = __osd_zap_create(env, osd_obj2dev(obj), &db, oh->ot_tx, la, parent,
1297 ZAP_FLAG_UINT64_KEY);
1303 static dmu_buf_t *osd_mkdir(const struct lu_env *env, struct osd_object *obj,
1304 struct lu_attr *la, uint64_t parent,
1305 struct osd_thandle *oh)
1310 LASSERT(S_ISDIR(la->la_mode));
1311 rc = __osd_zap_create(env, osd_obj2dev(obj), &db,
1312 oh->ot_tx, la, parent, 0);
1318 static dmu_buf_t *osd_mkreg(const struct lu_env *env, struct osd_object *obj,
1319 struct lu_attr *la, uint64_t parent,
1320 struct osd_thandle *oh)
1324 struct osd_device *osd = osd_obj2dev(obj);
1326 LASSERT(S_ISREG(la->la_mode));
1327 rc = __osd_object_create(env, obj, &db, oh->ot_tx, la, parent);
1332 * XXX: a hack, OST to use bigger blocksize. we need
1333 * a method in OSD API to control this from OFD/MDD
1335 if (!lu_device_is_md(osd2lu_dev(osd))) {
1336 rc = -dmu_object_set_blocksize(osd->od_os,
1338 128 << 10, 0, oh->ot_tx);
1340 CERROR("%s: can't change blocksize: %d\n",
1341 osd->od_svname, rc);
1349 static dmu_buf_t *osd_mksym(const struct lu_env *env, struct osd_object *obj,
1350 struct lu_attr *la, uint64_t parent,
1351 struct osd_thandle *oh)
1356 LASSERT(S_ISLNK(la->la_mode));
1357 rc = __osd_object_create(env, obj, &db, oh->ot_tx, la, parent);
1363 static dmu_buf_t *osd_mknod(const struct lu_env *env, struct osd_object *obj,
1364 struct lu_attr *la, uint64_t parent,
1365 struct osd_thandle *oh)
1370 la->la_valid = LA_MODE;
1371 if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode))
1372 la->la_valid |= LA_RDEV;
1374 rc = __osd_object_create(env, obj, &db, oh->ot_tx, la, parent);
1380 typedef dmu_buf_t *(*osd_obj_type_f)(const struct lu_env *env,
1381 struct osd_object *obj,
1384 struct osd_thandle *oh);
1386 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
1388 osd_obj_type_f result;
1414 * Primitives for directory (i.e. ZAP) handling
1416 static inline int osd_init_lma(const struct lu_env *env, struct osd_object *obj,
1417 const struct lu_fid *fid, struct osd_thandle *oh)
1419 struct osd_thread_info *info = osd_oti_get(env);
1420 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
1424 lustre_lma_init(lma, fid, 0, 0);
1425 lustre_lma_swab(lma);
1427 buf.lb_len = sizeof(*lma);
1429 rc = osd_xattr_set_internal(env, obj, &buf, XATTR_NAME_LMA,
1430 LU_XATTR_CREATE, oh);
1436 * Concurrency: @dt is write locked.
1438 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1439 struct lu_attr *attr,
1440 struct dt_allocation_hint *hint,
1441 struct dt_object_format *dof,
1444 struct zpl_direntry *zde = &osd_oti_get(env)->oti_zde.lzd_reg;
1445 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1446 struct osd_object *obj = osd_dt_obj(dt);
1447 struct osd_device *osd = osd_obj2dev(obj);
1448 char *buf = osd_oti_get(env)->oti_str;
1449 struct osd_thandle *oh;
1456 /* concurrent create declarations should not see
1457 * the object inconsistent (db, attr, etc).
1458 * in regular cases acquisition should be cheap */
1459 down(&obj->oo_guard);
1461 LASSERT(osd_invariant(obj));
1462 LASSERT(!dt_object_exists(dt));
1463 LASSERT(dof != NULL);
1465 LASSERT(th != NULL);
1466 oh = container_of0(th, struct osd_thandle, ot_super);
1469 * XXX missing: Quote handling.
1472 LASSERT(obj->oo_db == NULL);
1474 /* to follow ZFS on-disk format we need
1475 * to initialize parent dnode properly */
1477 if (hint && hint->dah_parent)
1478 zapid = osd_dt_obj(hint->dah_parent)->oo_db->db_object;
1480 db = osd_create_type_f(dof->dof_type)(env, obj, attr, zapid, oh);
1482 GOTO(out, rc = PTR_ERR(db));
1485 zde->zde_dnode = db->db_object;
1486 zde->zde_type = IFTODT(attr->la_mode & S_IFMT);
1488 zapid = osd_get_name_n_idx(env, osd, fid, buf);
1490 rc = -zap_add(osd->od_os, zapid, buf, 8, 1, zde, oh->ot_tx);
1494 /* Add new object to inode accounting.
1495 * Errors are not considered as fatal */
1496 rc = -zap_increment_int(osd->od_os, osd->od_iusr_oid,
1497 (attr->la_valid & LA_UID) ? attr->la_uid : 0, 1,
1500 CERROR("%s: failed to add "DFID" to accounting ZAP for usr %d "
1501 "(%d)\n", osd->od_svname, PFID(fid), attr->la_uid, rc);
1502 rc = -zap_increment_int(osd->od_os, osd->od_igrp_oid,
1503 (attr->la_valid & LA_GID) ? attr->la_gid : 0, 1,
1506 CERROR("%s: failed to add "DFID" to accounting ZAP for grp %d "
1507 "(%d)\n", osd->od_svname, PFID(fid), attr->la_gid, rc);
1509 /* configure new osd object */
1511 rc = osd_object_init0(env, obj);
1512 LASSERT(ergo(rc == 0, dt_object_exists(dt)));
1513 LASSERT(osd_invariant(obj));
1515 rc = osd_init_lma(env, obj, fid, oh);
1517 CERROR("%s: can not set LMA on "DFID": rc = %d\n",
1518 osd->od_svname, PFID(fid), rc);
1519 /* ignore errors during LMA initialization */
1528 static int osd_declare_object_ref_add(const struct lu_env *env,
1529 struct dt_object *dt,
1532 return osd_declare_attr_set(env, dt, NULL, th);
1536 * Concurrency: @dt is write locked.
1538 static int osd_object_ref_add(const struct lu_env *env,
1539 struct dt_object *dt,
1540 struct thandle *handle)
1542 struct osd_object *obj = osd_dt_obj(dt);
1543 struct osd_thandle *oh;
1544 struct osd_device *osd = osd_obj2dev(obj);
1550 LASSERT(osd_invariant(obj));
1551 LASSERT(dt_object_exists(dt));
1552 LASSERT(obj->oo_sa_hdl != NULL);
1554 oh = container_of0(handle, struct osd_thandle, ot_super);
1556 write_lock(&obj->oo_attr_lock);
1557 nlink = ++obj->oo_attr.la_nlink;
1558 write_unlock(&obj->oo_attr_lock);
1560 rc = osd_object_sa_update(obj, SA_ZPL_LINKS(osd), &nlink, 8, oh);
1564 static int osd_declare_object_ref_del(const struct lu_env *env,
1565 struct dt_object *dt,
1566 struct thandle *handle)
1568 return osd_declare_attr_set(env, dt, NULL, handle);
1572 * Concurrency: @dt is write locked.
1574 static int osd_object_ref_del(const struct lu_env *env,
1575 struct dt_object *dt,
1576 struct thandle *handle)
1578 struct osd_object *obj = osd_dt_obj(dt);
1579 struct osd_thandle *oh;
1580 struct osd_device *osd = osd_obj2dev(obj);
1586 LASSERT(osd_invariant(obj));
1587 LASSERT(dt_object_exists(dt));
1588 LASSERT(obj->oo_sa_hdl != NULL);
1590 oh = container_of0(handle, struct osd_thandle, ot_super);
1591 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
1593 write_lock(&obj->oo_attr_lock);
1594 nlink = --obj->oo_attr.la_nlink;
1595 write_unlock(&obj->oo_attr_lock);
1597 rc = osd_object_sa_update(obj, SA_ZPL_LINKS(osd), &nlink, 8, oh);
1601 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
1602 __u64 start, __u64 end)
1604 struct osd_device *osd = osd_obj2dev(osd_dt_obj(dt));
1607 /* XXX: no other option than syncing the whole filesystem until we
1608 * support ZIL. If the object tracked the txg that it was last
1609 * modified in, it could pass that txg here instead of "0". Maybe
1610 * the changes are already committed, so no wait is needed at all? */
1611 txg_wait_synced(dmu_objset_pool(osd->od_os), 0ULL);
1616 static struct dt_object_operations osd_obj_ops = {
1617 .do_read_lock = osd_object_read_lock,
1618 .do_write_lock = osd_object_write_lock,
1619 .do_read_unlock = osd_object_read_unlock,
1620 .do_write_unlock = osd_object_write_unlock,
1621 .do_write_locked = osd_object_write_locked,
1622 .do_attr_get = osd_attr_get,
1623 .do_declare_attr_set = osd_declare_attr_set,
1624 .do_attr_set = osd_attr_set,
1625 .do_ah_init = osd_ah_init,
1626 .do_declare_create = osd_declare_object_create,
1627 .do_create = osd_object_create,
1628 .do_declare_destroy = osd_declare_object_destroy,
1629 .do_destroy = osd_object_destroy,
1630 .do_index_try = osd_index_try,
1631 .do_declare_ref_add = osd_declare_object_ref_add,
1632 .do_ref_add = osd_object_ref_add,
1633 .do_declare_ref_del = osd_declare_object_ref_del,
1634 .do_ref_del = osd_object_ref_del,
1635 .do_xattr_get = osd_xattr_get,
1636 .do_declare_xattr_set = osd_declare_xattr_set,
1637 .do_xattr_set = osd_xattr_set,
1638 .do_declare_xattr_del = osd_declare_xattr_del,
1639 .do_xattr_del = osd_xattr_del,
1640 .do_xattr_list = osd_xattr_list,
1641 .do_object_sync = osd_object_sync,
1644 static struct lu_object_operations osd_lu_obj_ops = {
1645 .loo_object_init = osd_object_init,
1646 .loo_object_delete = osd_object_delete,
1647 .loo_object_release = osd_object_release,
1648 .loo_object_free = osd_object_free,
1649 .loo_object_print = osd_object_print,
1650 .loo_object_invariant = osd_object_invariant,
1653 static int osd_otable_it_attr_get(const struct lu_env *env,
1654 struct dt_object *dt,
1655 struct lu_attr *attr)
1661 static struct dt_object_operations osd_obj_otable_it_ops = {
1662 .do_attr_get = osd_otable_it_attr_get,
1663 .do_index_try = osd_index_try,