Whamcloud - gitweb
LU-3268 lod: support BE servers in lod_verify_striping()
[fs/lustre-release.git] / lustre / osd-zfs / osd_object.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * Copyright (c) 2012, 2013, Intel Corporation.
32  * Use is subject to license terms.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  *
38  * lustre/osd-zfs/osd_object.c
39  *
40  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
41  * Author: Mike Pershin <tappro@whamcloud.com>
42  * Author: Johann Lombardi <johann@whamcloud.com>
43  */
44
45 #ifndef EXPORT_SYMTAB
46 # define EXPORT_SYMTAB
47 #endif
48 #define DEBUG_SUBSYSTEM S_OSD
49
50 #include <lustre_ver.h>
51 #include <libcfs/libcfs.h>
52 #include <lustre_fsfilt.h>
53 #include <obd_support.h>
54 #include <lustre_net.h>
55 #include <obd.h>
56 #include <obd_class.h>
57 #include <lustre_disk.h>
58 #include <lustre_fid.h>
59
60 #include "osd_internal.h"
61
62 #include <sys/dnode.h>
63 #include <sys/dbuf.h>
64 #include <sys/spa.h>
65 #include <sys/stat.h>
66 #include <sys/zap.h>
67 #include <sys/spa_impl.h>
68 #include <sys/zfs_znode.h>
69 #include <sys/dmu_tx.h>
70 #include <sys/dmu_objset.h>
71 #include <sys/dsl_prop.h>
72 #include <sys/sa_impl.h>
73 #include <sys/txg.h>
74
75 static char *osd_obj_tag = "osd_object";
76
77 static struct dt_object_operations osd_obj_ops;
78 static struct lu_object_operations osd_lu_obj_ops;
79 extern struct dt_body_operations osd_body_ops;
80 static struct dt_object_operations osd_obj_otable_it_ops;
81
82 extern cfs_mem_cache_t *osd_object_kmem;
83
84 static void
85 osd_object_sa_fini(struct osd_object *obj)
86 {
87         if (obj->oo_sa_hdl) {
88                 sa_handle_destroy(obj->oo_sa_hdl);
89                 obj->oo_sa_hdl = NULL;
90         }
91 }
92
93 static int
94 osd_object_sa_init(struct osd_object *obj, udmu_objset_t *uos)
95 {
96         int rc;
97
98         LASSERT(obj->oo_sa_hdl == NULL);
99         LASSERT(obj->oo_db != NULL);
100
101         rc = -sa_handle_get(uos->os, obj->oo_db->db_object, obj,
102                             SA_HDL_PRIVATE, &obj->oo_sa_hdl);
103         if (rc)
104                 return rc;
105
106         /* Cache the xattr object id, valid for the life of the object */
107         rc = -sa_lookup(obj->oo_sa_hdl, SA_ZPL_XATTR(uos), &obj->oo_xattr, 8);
108         if (rc == -ENOENT) {
109                 obj->oo_xattr = ZFS_NO_OBJECT;
110                 rc = 0;
111         } else if (rc) {
112                 osd_object_sa_fini(obj);
113         }
114
115         return rc;
116 }
117
118 /*
119  * Add object to list of dirty objects in tx handle.
120  */
121 static void
122 osd_object_sa_dirty_add(struct osd_object *obj, struct osd_thandle *oh)
123 {
124         if (!cfs_list_empty(&obj->oo_sa_linkage))
125                 return;
126
127         down(&oh->ot_sa_lock);
128         write_lock(&obj->oo_attr_lock);
129         if (likely(cfs_list_empty(&obj->oo_sa_linkage)))
130                 cfs_list_add(&obj->oo_sa_linkage, &oh->ot_sa_list);
131         write_unlock(&obj->oo_attr_lock);
132         up(&oh->ot_sa_lock);
133 }
134
135 /*
136  * Release spill block dbuf hold for all dirty SAs.
137  */
138 void osd_object_sa_dirty_rele(struct osd_thandle *oh)
139 {
140         struct osd_object *obj;
141
142         down(&oh->ot_sa_lock);
143         while (!cfs_list_empty(&oh->ot_sa_list)) {
144                 obj = cfs_list_entry(oh->ot_sa_list.next,
145                                      struct osd_object, oo_sa_linkage);
146                 sa_spill_rele(obj->oo_sa_hdl);
147                 write_lock(&obj->oo_attr_lock);
148                 cfs_list_del_init(&obj->oo_sa_linkage);
149                 write_unlock(&obj->oo_attr_lock);
150         }
151         up(&oh->ot_sa_lock);
152 }
153
154 /*
155  * Update the SA and add the object to the dirty list.
156  */
157 int osd_object_sa_update(struct osd_object *obj, sa_attr_type_t type,
158                          void *buf, uint32_t buflen, struct osd_thandle *oh)
159 {
160         int rc;
161
162         LASSERT(obj->oo_sa_hdl != NULL);
163         LASSERT(oh->ot_tx != NULL);
164
165         rc = -sa_update(obj->oo_sa_hdl, type, buf, buflen, oh->ot_tx);
166         osd_object_sa_dirty_add(obj, oh);
167
168         return rc;
169 }
170
171 /*
172  * Bulk update the SA and add the object to the dirty list.
173  */
174 static int
175 osd_object_sa_bulk_update(struct osd_object *obj, sa_bulk_attr_t *attrs,
176                           int count, struct osd_thandle *oh)
177 {
178         int rc;
179
180         LASSERT(obj->oo_sa_hdl != NULL);
181         LASSERT(oh->ot_tx != NULL);
182
183         rc = -sa_bulk_update(obj->oo_sa_hdl, attrs, count, oh->ot_tx);
184         osd_object_sa_dirty_add(obj, oh);
185
186         return rc;
187 }
188
189 /*
190  * Retrieve the attributes of a DMU object
191  */
192 int __osd_object_attr_get(const struct lu_env *env, udmu_objset_t *uos,
193                           struct osd_object *obj, struct lu_attr *la)
194 {
195         struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
196         sa_handle_t     *sa_hdl;
197         sa_bulk_attr_t  *bulk;
198         int              cnt = 0;
199         int              rc;
200         ENTRY;
201
202         LASSERT(obj->oo_db != NULL);
203
204         rc = -sa_handle_get(uos->os, obj->oo_db->db_object, NULL,
205                             SA_HDL_PRIVATE, &sa_hdl);
206         if (rc)
207                 RETURN(rc);
208
209         OBD_ALLOC(bulk, sizeof(sa_bulk_attr_t) * 9);
210         if (bulk == NULL)
211                 GOTO(out_sa, rc = -ENOMEM);
212
213         la->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE | LA_TYPE |
214                         LA_SIZE | LA_UID | LA_GID | LA_FLAGS | LA_NLINK;
215
216         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(uos), NULL, osa->atime, 16);
217         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(uos), NULL, osa->mtime, 16);
218         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(uos), NULL, osa->ctime, 16);
219         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(uos), NULL, &osa->mode, 8);
220         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_SIZE(uos), NULL, &osa->size, 8);
221         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(uos), NULL, &osa->nlink, 8);
222         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_UID(uos), NULL, &osa->uid, 8);
223         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_GID(uos), NULL, &osa->gid, 8);
224         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(uos), NULL, &osa->flags, 8);
225
226         rc = -sa_bulk_lookup(sa_hdl, bulk, cnt);
227         if (rc)
228                 GOTO(out_bulk, rc);
229
230         la->la_atime = osa->atime[0];
231         la->la_mtime = osa->mtime[0];
232         la->la_ctime = osa->ctime[0];
233         la->la_mode = osa->mode;
234         la->la_uid = osa->uid;
235         la->la_gid = osa->gid;
236         la->la_nlink = osa->nlink;
237         la->la_flags = attrs_zfs2fs(osa->flags);
238         la->la_size = osa->size;
239
240         if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode)) {
241                 rc = -sa_lookup(sa_hdl, SA_ZPL_RDEV(uos), &osa->rdev, 8);
242                 if (rc)
243                         GOTO(out_bulk, rc);
244                 la->la_rdev = osa->rdev;
245                 la->la_valid |= LA_RDEV;
246         }
247 out_bulk:
248         OBD_FREE(bulk, sizeof(sa_bulk_attr_t) * 9);
249 out_sa:
250         sa_handle_destroy(sa_hdl);
251
252         RETURN(rc);
253 }
254
255 int __osd_obj2dbuf(const struct lu_env *env, objset_t *os,
256                    uint64_t oid, dmu_buf_t **dbp, void *tag)
257 {
258         dmu_object_info_t *doi = &osd_oti_get(env)->oti_doi;
259         int rc;
260
261         LASSERT(tag);
262
263         rc = -sa_buf_hold(os, oid, tag, dbp);
264         if (rc)
265                 return rc;
266
267         dmu_object_info_from_db(*dbp, doi);
268         if (unlikely (oid != DMU_USERUSED_OBJECT &&
269             oid != DMU_GROUPUSED_OBJECT && doi->doi_bonus_type != DMU_OT_SA)) {
270                 sa_buf_rele(*dbp, tag);
271                 *dbp = NULL;
272                 return -EINVAL;
273         }
274
275         LASSERT(*dbp);
276         LASSERT((*dbp)->db_object == oid);
277         LASSERT((*dbp)->db_offset == -1);
278         LASSERT((*dbp)->db_data != NULL);
279
280         return 0;
281 }
282
283 /*
284  * Concurrency: no concurrent access is possible that early in object
285  * life-cycle.
286  */
287 struct lu_object *osd_object_alloc(const struct lu_env *env,
288                                    const struct lu_object_header *hdr,
289                                    struct lu_device *d)
290 {
291         struct osd_object *mo;
292
293         OBD_SLAB_ALLOC_PTR_GFP(mo, osd_object_kmem, CFS_ALLOC_IO);
294         if (mo != NULL) {
295                 struct lu_object *l;
296
297                 l = &mo->oo_dt.do_lu;
298                 dt_object_init(&mo->oo_dt, NULL, d);
299                 mo->oo_dt.do_ops = &osd_obj_ops;
300                 l->lo_ops = &osd_lu_obj_ops;
301                 CFS_INIT_LIST_HEAD(&mo->oo_sa_linkage);
302                 init_rwsem(&mo->oo_sem);
303                 sema_init(&mo->oo_guard, 1);
304                 rwlock_init(&mo->oo_attr_lock);
305                 return l;
306         } else {
307                 return NULL;
308         }
309 }
310
311 /*
312  * Concurrency: shouldn't matter.
313  */
314 int osd_object_init0(const struct lu_env *env, struct osd_object *obj)
315 {
316         struct osd_device       *osd = osd_obj2dev(obj);
317         udmu_objset_t           *uos = &osd->od_objset;
318         const struct lu_fid     *fid  = lu_object_fid(&obj->oo_dt.do_lu);
319         int                      rc = 0;
320         ENTRY;
321
322         if (obj->oo_db == NULL)
323                 RETURN(0);
324
325         /* object exist */
326
327         rc = osd_object_sa_init(obj, uos);
328         if (rc)
329                 RETURN(rc);
330
331         /* cache attrs in object */
332         rc = __osd_object_attr_get(env, &osd->od_objset,
333                                    obj, &obj->oo_attr);
334         if (rc)
335                 RETURN(rc);
336
337         if (likely(!fid_is_acct(fid)))
338                 /* no body operations for accounting objects */
339                 obj->oo_dt.do_body_ops = &osd_body_ops;
340
341         /*
342          * initialize object before marking it existing
343          */
344         obj->oo_dt.do_lu.lo_header->loh_attr |= obj->oo_attr.la_mode & S_IFMT;
345
346         cfs_mb();
347         obj->oo_dt.do_lu.lo_header->loh_attr |= LOHA_EXISTS;
348
349         RETURN(0);
350 }
351
352 static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
353 {
354         struct osd_thread_info  *info = osd_oti_get(env);
355         struct lu_buf           buf;
356         int                     rc;
357         struct lustre_mdt_attrs *lma;
358         ENTRY;
359
360         CLASSERT(sizeof(info->oti_buf) >= sizeof(*lma));
361         lma = (struct lustre_mdt_attrs *)info->oti_buf;
362         buf.lb_buf = lma;
363         buf.lb_len = sizeof(info->oti_buf);
364
365         rc = osd_xattr_get(env, &obj->oo_dt, &buf, XATTR_NAME_LMA, BYPASS_CAPA);
366         if (rc > 0) {
367                 rc = 0;
368                 lustre_lma_swab(lma);
369                 if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
370                              CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT))) {
371                         CWARN("%s: unsupported incompat LMA feature(s) %#x for "
372                               "fid = "DFID"\n", osd_obj2dev(obj)->od_svname,
373                               lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
374                               PFID(lu_object_fid(&obj->oo_dt.do_lu)));
375                         rc = -EOPNOTSUPP;
376                 }
377         } else if (rc == -ENODATA) {
378                 /* haven't initialize LMA xattr */
379                 rc = 0;
380         }
381
382         RETURN(rc);
383 }
384
385 /*
386  * Concurrency: no concurrent access is possible that early in object
387  * life-cycle.
388  */
389 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
390                            const struct lu_object_conf *conf)
391 {
392         struct osd_object       *obj = osd_obj(l);
393         struct osd_device       *osd = osd_obj2dev(obj);
394         uint64_t                 oid;
395         int                      rc;
396         ENTRY;
397
398         LASSERT(osd_invariant(obj));
399
400         if (fid_is_otable_it(&l->lo_header->loh_fid)) {
401                 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
402                 l->lo_header->loh_attr |= LOHA_EXISTS;
403                 RETURN(0);
404         }
405
406         rc = osd_fid_lookup(env, osd, lu_object_fid(l), &oid);
407         if (rc == 0) {
408                 LASSERT(obj->oo_db == NULL);
409                 rc = __osd_obj2dbuf(env, osd->od_objset.os, oid,
410                                         &obj->oo_db, osd_obj_tag);
411                 if (rc != 0) {
412                         CERROR("%s: lookup "DFID"/"LPX64" failed: rc = %d\n",
413                                osd->od_svname, PFID(lu_object_fid(l)), oid, rc);
414                         GOTO(out, rc);
415                 }
416                 LASSERT(obj->oo_db);
417                 rc = osd_object_init0(env, obj);
418                 if (rc != 0)
419                         GOTO(out, rc);
420
421                 rc = osd_check_lma(env, obj);
422                 if (rc != 0)
423                         GOTO(out, rc);
424         } else if (rc == -ENOENT) {
425                 rc = 0;
426         }
427         LASSERT(osd_invariant(obj));
428 out:
429         RETURN(rc);
430 }
431
432 /*
433  * Concurrency: no concurrent access is possible that late in object
434  * life-cycle.
435  */
436 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
437 {
438         struct osd_object *obj = osd_obj(l);
439
440         LASSERT(osd_invariant(obj));
441
442         dt_object_fini(&obj->oo_dt);
443         OBD_SLAB_FREE_PTR(obj, osd_object_kmem);
444 }
445
446 static void __osd_declare_object_destroy(const struct lu_env *env,
447                                          struct osd_object *obj,
448                                          struct osd_thandle *oh)
449 {
450         struct osd_device       *osd = osd_obj2dev(obj);
451         udmu_objset_t           *uos = &osd->od_objset;
452         dmu_buf_t               *db = obj->oo_db;
453         zap_attribute_t         *za = &osd_oti_get(env)->oti_za;
454         uint64_t                 oid = db->db_object, xid;
455         dmu_tx_t                *tx = oh->ot_tx;
456         zap_cursor_t            *zc;
457         int                      rc = 0;
458
459         dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END);
460
461         /* zap holding xattrs */
462         if (obj->oo_xattr != ZFS_NO_OBJECT) {
463                 oid = obj->oo_xattr;
464
465                 dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END);
466
467                 rc = -udmu_zap_cursor_init(&zc, uos, oid, 0);
468                 if (rc)
469                         goto out;
470
471                 while ((rc = -zap_cursor_retrieve(zc, za)) == 0) {
472                         BUG_ON(za->za_integer_length != sizeof(uint64_t));
473                         BUG_ON(za->za_num_integers != 1);
474
475                         rc = -zap_lookup(uos->os, obj->oo_xattr, za->za_name,
476                                          sizeof(uint64_t), 1, &xid);
477                         if (rc) {
478                                 CERROR("%s: xattr lookup failed: rc = %d\n",
479                                        osd->od_svname, rc);
480                                 goto out_err;
481                         }
482                         dmu_tx_hold_free(tx, xid, 0, DMU_OBJECT_END);
483
484                         zap_cursor_advance(zc);
485                 }
486                 if (rc == -ENOENT)
487                         rc = 0;
488 out_err:
489                 udmu_zap_cursor_fini(zc);
490         }
491 out:
492         if (rc && tx->tx_err == 0)
493                 tx->tx_err = -rc;
494 }
495
496 static int osd_declare_object_destroy(const struct lu_env *env,
497                                       struct dt_object *dt,
498                                       struct thandle *th)
499 {
500         char                    *buf = osd_oti_get(env)->oti_str;
501         const struct lu_fid     *fid = lu_object_fid(&dt->do_lu);
502         struct osd_object       *obj = osd_dt_obj(dt);
503         struct osd_device       *osd = osd_obj2dev(obj);
504         struct osd_thandle      *oh;
505         uint64_t                 zapid;
506         int                      rc;
507         ENTRY;
508
509         LASSERT(th != NULL);
510         LASSERT(dt_object_exists(dt));
511
512         oh = container_of0(th, struct osd_thandle, ot_super);
513         LASSERT(oh->ot_tx != NULL);
514
515         /* declare that we'll destroy the object */
516         __osd_declare_object_destroy(env, obj, oh);
517
518         /* declare that we'll remove object from fid-dnode mapping */
519         zapid = osd_get_name_n_idx(env, osd, fid, buf);
520         dmu_tx_hold_bonus(oh->ot_tx, zapid);
521         dmu_tx_hold_zap(oh->ot_tx, zapid, 0, buf);
522
523         /* declare that we'll remove object from inode accounting ZAPs */
524         dmu_tx_hold_bonus(oh->ot_tx, osd->od_iusr_oid);
525         dmu_tx_hold_zap(oh->ot_tx, osd->od_iusr_oid, 0, buf);
526         dmu_tx_hold_bonus(oh->ot_tx, osd->od_igrp_oid);
527         dmu_tx_hold_zap(oh->ot_tx, osd->od_igrp_oid, 0, buf);
528
529         /* one less inode */
530         rc = osd_declare_quota(env, osd, obj->oo_attr.la_uid,
531                                obj->oo_attr.la_gid, -1, oh, false, NULL, false);
532         if (rc)
533                 RETURN(rc);
534
535         /* data to be truncated */
536         rc = osd_declare_quota(env, osd, obj->oo_attr.la_uid,
537                                obj->oo_attr.la_gid, 0, oh, true, NULL, false);
538         RETURN(rc);
539 }
540
541 int __osd_object_free(udmu_objset_t *uos, uint64_t oid, dmu_tx_t *tx)
542 {
543         LASSERT(uos->objects != 0);
544         spin_lock(&uos->lock);
545         uos->objects--;
546         spin_unlock(&uos->lock);
547
548         return -dmu_object_free(uos->os, oid, tx);
549 }
550
551 /*
552  * Delete a DMU object
553  *
554  * The transaction passed to this routine must have
555  * dmu_tx_hold_free(tx, oid, 0, DMU_OBJECT_END) called
556  * and then assigned to a transaction group.
557  *
558  * This will release db and set it to NULL to prevent further dbuf releases.
559  */
560 static int __osd_object_destroy(const struct lu_env *env,
561                                 struct osd_object *obj,
562                                 dmu_tx_t *tx, void *tag)
563 {
564         struct osd_device       *osd = osd_obj2dev(obj);
565         udmu_objset_t           *uos = &osd->od_objset;
566         uint64_t                 xid;
567         zap_attribute_t         *za = &osd_oti_get(env)->oti_za;
568         zap_cursor_t            *zc;
569         int                      rc;
570
571         /* Assert that the transaction has been assigned to a
572            transaction group. */
573         LASSERT(tx->tx_txg != 0);
574
575         /* zap holding xattrs */
576         if (obj->oo_xattr != ZFS_NO_OBJECT) {
577                 rc = -udmu_zap_cursor_init(&zc, uos, obj->oo_xattr, 0);
578                 if (rc)
579                         return rc;
580                 while ((rc = -zap_cursor_retrieve(zc, za)) == 0) {
581                         BUG_ON(za->za_integer_length != sizeof(uint64_t));
582                         BUG_ON(za->za_num_integers != 1);
583
584                         rc = -zap_lookup(uos->os, obj->oo_xattr, za->za_name,
585                                          sizeof(uint64_t), 1, &xid);
586                         if (rc) {
587                                 CERROR("%s: lookup xattr %s failed: rc = %d\n",
588                                        osd->od_svname, za->za_name, rc);
589                                 continue;
590                         }
591                         rc = __osd_object_free(uos, xid, tx);
592                         if (rc)
593                                 CERROR("%s: fetch xattr %s failed: rc = %d\n",
594                                        osd->od_svname, za->za_name, rc);
595                         zap_cursor_advance(zc);
596                 }
597                 udmu_zap_cursor_fini(zc);
598
599                 rc = __osd_object_free(uos, obj->oo_xattr, tx);
600                 if (rc)
601                         CERROR("%s: freeing xattr failed: rc = %d\n",
602                                osd->od_svname, rc);
603         }
604
605         return __osd_object_free(uos, obj->oo_db->db_object, tx);
606 }
607
608 static int osd_object_destroy(const struct lu_env *env,
609                               struct dt_object *dt,
610                               struct thandle *th)
611 {
612         char                    *buf = osd_oti_get(env)->oti_str;
613         struct osd_object       *obj = osd_dt_obj(dt);
614         struct osd_device       *osd = osd_obj2dev(obj);
615         const struct lu_fid     *fid = lu_object_fid(&dt->do_lu);
616         struct osd_thandle      *oh;
617         int                      rc;
618         uint64_t                 zapid;
619         ENTRY;
620
621         LASSERT(obj->oo_db != NULL);
622         LASSERT(dt_object_exists(dt));
623         LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
624
625         oh = container_of0(th, struct osd_thandle, ot_super);
626         LASSERT(oh != NULL);
627         LASSERT(oh->ot_tx != NULL);
628
629         zapid = osd_get_name_n_idx(env, osd, fid, buf);
630
631         /* remove obj ref from index dir (it depends) */
632         rc = -zap_remove(osd->od_objset.os, zapid, buf, oh->ot_tx);
633         if (rc) {
634                 CERROR("%s: zap_remove() failed: rc = %d\n",
635                        osd->od_svname, rc);
636                 GOTO(out, rc);
637         }
638
639         /* Remove object from inode accounting. It is not fatal for the destroy
640          * operation if something goes wrong while updating accounting, but we
641          * still log an error message to notify the administrator */
642         rc = -zap_increment_int(osd->od_objset.os, osd->od_iusr_oid,
643                         obj->oo_attr.la_uid, -1, oh->ot_tx);
644         if (rc)
645                 CERROR("%s: failed to remove "DFID" from accounting ZAP for usr"
646                         " %d: rc = %d\n", osd->od_svname, PFID(fid),
647                         obj->oo_attr.la_uid, rc);
648         rc = -zap_increment_int(osd->od_objset.os, osd->od_igrp_oid,
649                                 obj->oo_attr.la_gid, -1, oh->ot_tx);
650         if (rc)
651                 CERROR("%s: failed to remove "DFID" from accounting ZAP for grp"
652                         " %d: rc = %d\n", osd->od_svname, PFID(fid),
653                         obj->oo_attr.la_gid, rc);
654
655         /* kill object */
656         rc = __osd_object_destroy(env, obj, oh->ot_tx, osd_obj_tag);
657         if (rc) {
658                 CERROR("%s: __osd_object_destroy() failed: rc = %d\n",
659                        osd->od_svname, rc);
660                 GOTO(out, rc);
661         }
662
663 out:
664         /* not needed in the cache anymore */
665         set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
666
667         RETURN (0);
668 }
669
670 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
671 {
672         struct osd_object *obj = osd_obj(l);
673
674         if (obj->oo_db != NULL) {
675                 osd_object_sa_fini(obj);
676                 if (obj->oo_sa_xattr) {
677                         nvlist_free(obj->oo_sa_xattr);
678                         obj->oo_sa_xattr = NULL;
679                 }
680                 sa_buf_rele(obj->oo_db, osd_obj_tag);
681                 cfs_list_del(&obj->oo_sa_linkage);
682                 obj->oo_db = NULL;
683         }
684 }
685
686 /*
687  * Concurrency: ->loo_object_release() is called under site spin-lock.
688  */
689 static void osd_object_release(const struct lu_env *env,
690                                struct lu_object *l)
691 {
692 }
693
694 /*
695  * Concurrency: shouldn't matter.
696  */
697 static int osd_object_print(const struct lu_env *env, void *cookie,
698                             lu_printer_t p, const struct lu_object *l)
699 {
700         struct osd_object *o = osd_obj(l);
701
702         return (*p)(env, cookie, LUSTRE_OSD_ZFS_NAME"-object@%p", o);
703 }
704
705 static void osd_object_read_lock(const struct lu_env *env,
706                                  struct dt_object *dt, unsigned role)
707 {
708         struct osd_object *obj = osd_dt_obj(dt);
709
710         LASSERT(osd_invariant(obj));
711
712         down_read(&obj->oo_sem);
713 }
714
715 static void osd_object_write_lock(const struct lu_env *env,
716                                   struct dt_object *dt, unsigned role)
717 {
718         struct osd_object *obj = osd_dt_obj(dt);
719
720         LASSERT(osd_invariant(obj));
721
722         down_write(&obj->oo_sem);
723 }
724
725 static void osd_object_read_unlock(const struct lu_env *env,
726                                    struct dt_object *dt)
727 {
728         struct osd_object *obj = osd_dt_obj(dt);
729
730         LASSERT(osd_invariant(obj));
731         up_read(&obj->oo_sem);
732 }
733
734 static void osd_object_write_unlock(const struct lu_env *env,
735                                     struct dt_object *dt)
736 {
737         struct osd_object *obj = osd_dt_obj(dt);
738
739         LASSERT(osd_invariant(obj));
740         up_write(&obj->oo_sem);
741 }
742
743 static int osd_object_write_locked(const struct lu_env *env,
744                                    struct dt_object *dt)
745 {
746         struct osd_object *obj = osd_dt_obj(dt);
747         int rc = 1;
748
749         LASSERT(osd_invariant(obj));
750
751         if (down_write_trylock(&obj->oo_sem)) {
752                 rc = 0;
753                 up_write(&obj->oo_sem);
754         }
755         return rc;
756 }
757
758 static int osd_attr_get(const struct lu_env *env,
759                         struct dt_object *dt,
760                         struct lu_attr *attr,
761                         struct lustre_capa *capa)
762 {
763         struct osd_object       *obj = osd_dt_obj(dt);
764         uint64_t                 blocks;
765         uint32_t                 blksize;
766
767         LASSERT(dt_object_exists(dt));
768         LASSERT(osd_invariant(obj));
769         LASSERT(obj->oo_db);
770
771         read_lock(&obj->oo_attr_lock);
772         *attr = obj->oo_attr;
773         read_unlock(&obj->oo_attr_lock);
774
775         /* with ZFS_DEBUG zrl_add_debug() called by DB_DNODE_ENTER()
776          * from within sa_object_size() can block on a mutex, so
777          * we can't call sa_object_size() holding rwlock */
778         sa_object_size(obj->oo_sa_hdl, &blksize, &blocks);
779         /* we do not control size of indices, so always calculate
780          * it from number of blocks reported by DMU */
781         if (S_ISDIR(attr->la_mode))
782                 attr->la_size = 512 * blocks;
783         /* Block size may be not set; suggest maximal I/O transfers. */
784         if (blksize == 0)
785                 blksize = 1ULL << SPA_MAXBLOCKSHIFT;
786
787         attr->la_blksize = blksize;
788         attr->la_blocks = blocks;
789         attr->la_valid |= LA_BLOCKS | LA_BLKSIZE;
790
791         return 0;
792 }
793
794 /* Simple wrapper on top of qsd API which implement quota transfer for osd
795  * setattr needs. As a reminder, only the root user can change ownership of
796  * a file, that's why EDQUOT & EINPROGRESS errors are discarded */
797 static inline int qsd_transfer(const struct lu_env *env,
798                                struct qsd_instance *qsd,
799                                struct lquota_trans *trans, int qtype,
800                                __u64 orig_id, __u64 new_id, __u64 bspace,
801                                struct lquota_id_info *qi)
802 {
803         int     rc;
804
805         if (unlikely(qsd == NULL))
806                 return 0;
807
808         LASSERT(qtype >= 0 && qtype < MAXQUOTAS);
809         qi->lqi_type = qtype;
810
811         /* inode accounting */
812         qi->lqi_is_blk = false;
813
814         /* one more inode for the new owner ... */
815         qi->lqi_id.qid_uid = new_id;
816         qi->lqi_space      = 1;
817         rc = qsd_op_begin(env, qsd, trans, qi, NULL);
818         if (rc == -EDQUOT || rc == -EINPROGRESS)
819                 rc = 0;
820         if (rc)
821                 return rc;
822
823         /* and one less inode for the current id */
824         qi->lqi_id.qid_uid = orig_id;;
825         qi->lqi_space      = -1;
826         /* can't get EDQUOT when reducing usage */
827         rc = qsd_op_begin(env, qsd, trans, qi, NULL);
828         if (rc == -EINPROGRESS)
829                 rc = 0;
830         if (rc)
831                 return rc;
832
833         /* block accounting */
834         qi->lqi_is_blk = true;
835
836         /* more blocks for the new owner ... */
837         qi->lqi_id.qid_uid = new_id;
838         qi->lqi_space      = bspace;
839         rc = qsd_op_begin(env, qsd, trans, qi, NULL);
840         if (rc == -EDQUOT || rc == -EINPROGRESS)
841                 rc = 0;
842         if (rc)
843                 return rc;
844
845         /* and finally less blocks for the current owner */
846         qi->lqi_id.qid_uid = orig_id;
847         qi->lqi_space      = -bspace;
848         rc = qsd_op_begin(env, qsd, trans, qi, NULL);
849         /* can't get EDQUOT when reducing usage */
850         if (rc == -EINPROGRESS)
851                 rc = 0;
852         return rc;
853 }
854
855 static int osd_declare_attr_set(const struct lu_env *env,
856                                 struct dt_object *dt,
857                                 const struct lu_attr *attr,
858                                 struct thandle *handle)
859 {
860         struct osd_thread_info  *info = osd_oti_get(env);
861         char                    *buf = osd_oti_get(env)->oti_str;
862         struct osd_object       *obj = osd_dt_obj(dt);
863         struct osd_device       *osd = osd_obj2dev(obj);
864         struct osd_thandle      *oh;
865         uint64_t                 bspace;
866         uint32_t                 blksize;
867         int                      rc;
868         ENTRY;
869
870         if (!dt_object_exists(dt)) {
871                 /* XXX: sanity check that object creation is declared */
872                 RETURN(0);
873         }
874
875         LASSERT(handle != NULL);
876         LASSERT(osd_invariant(obj));
877
878         oh = container_of0(handle, struct osd_thandle, ot_super);
879
880         LASSERT(obj->oo_sa_hdl != NULL);
881         dmu_tx_hold_sa(oh->ot_tx, obj->oo_sa_hdl, 0);
882
883         sa_object_size(obj->oo_sa_hdl, &blksize, &bspace);
884         bspace = toqb(bspace * blksize);
885
886         if (attr && attr->la_valid & LA_UID) {
887                 /* account for user inode tracking ZAP update */
888                 dmu_tx_hold_bonus(oh->ot_tx, osd->od_iusr_oid);
889                 dmu_tx_hold_zap(oh->ot_tx, osd->od_iusr_oid, TRUE, buf);
890
891                 /* quota enforcement for user */
892                 if (attr->la_uid != obj->oo_attr.la_uid) {
893                         rc = qsd_transfer(env, osd->od_quota_slave,
894                                           &oh->ot_quota_trans, USRQUOTA,
895                                           obj->oo_attr.la_uid, attr->la_uid,
896                                           bspace, &info->oti_qi);
897                         if (rc)
898                                 RETURN(rc);
899                 }
900         }
901         if (attr && attr->la_valid & LA_GID) {
902                 /* account for user inode tracking ZAP update */
903                 dmu_tx_hold_bonus(oh->ot_tx, osd->od_igrp_oid);
904                 dmu_tx_hold_zap(oh->ot_tx, osd->od_igrp_oid, TRUE, buf);
905
906                 /* quota enforcement for group */
907                 if (attr->la_gid != obj->oo_attr.la_gid) {
908                         rc = qsd_transfer(env, osd->od_quota_slave,
909                                           &oh->ot_quota_trans, GRPQUOTA,
910                                           obj->oo_attr.la_gid, attr->la_gid,
911                                           bspace, &info->oti_qi);
912                         if (rc)
913                                 RETURN(rc);
914                 }
915         }
916
917         RETURN(0);
918 }
919
920 /*
921  * Set the attributes of an object
922  *
923  * The transaction passed to this routine must have
924  * dmu_tx_hold_bonus(tx, oid) called and then assigned
925  * to a transaction group.
926  */
927 static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
928                         const struct lu_attr *la, struct thandle *handle,
929                         struct lustre_capa *capa)
930 {
931         struct osd_object       *obj = osd_dt_obj(dt);
932         struct osd_device       *osd = osd_obj2dev(obj);
933         udmu_objset_t           *uos = &osd->od_objset;
934         struct osd_thandle      *oh;
935         struct osa_attr         *osa = &osd_oti_get(env)->oti_osa;
936         sa_bulk_attr_t          *bulk;
937         int                      cnt;
938         int                      rc = 0;
939
940         ENTRY;
941         LASSERT(handle != NULL);
942         LASSERT(dt_object_exists(dt));
943         LASSERT(osd_invariant(obj));
944         LASSERT(obj->oo_sa_hdl);
945
946         oh = container_of0(handle, struct osd_thandle, ot_super);
947         /* Assert that the transaction has been assigned to a
948            transaction group. */
949         LASSERT(oh->ot_tx->tx_txg != 0);
950
951         if (la->la_valid == 0)
952                 RETURN(0);
953
954         OBD_ALLOC(bulk, sizeof(sa_bulk_attr_t) * 10);
955         if (bulk == NULL)
956                 RETURN(-ENOMEM);
957
958         /* do both accounting updates outside oo_attr_lock below */
959         if ((la->la_valid & LA_UID) && (la->la_uid != obj->oo_attr.la_uid)) {
960                 /* Update user accounting. Failure isn't fatal, but we still
961                  * log an error message */
962                 rc = -zap_increment_int(osd->od_objset.os, osd->od_iusr_oid,
963                                         la->la_uid, 1, oh->ot_tx);
964                 if (rc)
965                         CERROR("%s: failed to update accounting ZAP for user "
966                                 "%d (%d)\n", osd->od_svname, la->la_uid, rc);
967                 rc = -zap_increment_int(osd->od_objset.os, osd->od_iusr_oid,
968                                         obj->oo_attr.la_uid, -1, oh->ot_tx);
969                 if (rc)
970                         CERROR("%s: failed to update accounting ZAP for user "
971                                 "%d (%d)\n", osd->od_svname,
972                                 obj->oo_attr.la_uid, rc);
973         }
974         if ((la->la_valid & LA_GID) && (la->la_gid != obj->oo_attr.la_gid)) {
975                 /* Update group accounting. Failure isn't fatal, but we still
976                  * log an error message */
977                 rc = -zap_increment_int(osd->od_objset.os, osd->od_igrp_oid,
978                                         la->la_gid, 1, oh->ot_tx);
979                 if (rc)
980                         CERROR("%s: failed to update accounting ZAP for user "
981                                 "%d (%d)\n", osd->od_svname, la->la_gid, rc);
982                 rc = -zap_increment_int(osd->od_objset.os, osd->od_igrp_oid,
983                                         obj->oo_attr.la_gid, -1, oh->ot_tx);
984                 if (rc)
985                         CERROR("%s: failed to update accounting ZAP for user "
986                                 "%d (%d)\n", osd->od_svname,
987                                 obj->oo_attr.la_gid, rc);
988         }
989
990         write_lock(&obj->oo_attr_lock);
991         cnt = 0;
992         if (la->la_valid & LA_ATIME) {
993                 osa->atime[0] = obj->oo_attr.la_atime = la->la_atime;
994                 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(uos), NULL,
995                                  osa->atime, 16);
996         }
997         if (la->la_valid & LA_MTIME) {
998                 osa->mtime[0] = obj->oo_attr.la_mtime = la->la_mtime;
999                 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(uos), NULL,
1000                                  osa->mtime, 16);
1001         }
1002         if (la->la_valid & LA_CTIME) {
1003                 osa->ctime[0] = obj->oo_attr.la_ctime = la->la_ctime;
1004                 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(uos), NULL,
1005                                  osa->ctime, 16);
1006         }
1007         if (la->la_valid & LA_MODE) {
1008                 /* mode is stored along with type, so read it first */
1009                 obj->oo_attr.la_mode = (obj->oo_attr.la_mode & S_IFMT) |
1010                         (la->la_mode & ~S_IFMT);
1011                 osa->mode = obj->oo_attr.la_mode;
1012                 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(uos), NULL,
1013                                  &osa->mode, 8);
1014         }
1015         if (la->la_valid & LA_SIZE) {
1016                 osa->size = obj->oo_attr.la_size = la->la_size;
1017                 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_SIZE(uos), NULL,
1018                                  &osa->size, 8);
1019         }
1020         if (la->la_valid & LA_NLINK) {
1021                 osa->nlink = obj->oo_attr.la_nlink = la->la_nlink;
1022                 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(uos), NULL,
1023                                  &osa->nlink, 8);
1024         }
1025         if (la->la_valid & LA_RDEV) {
1026                 osa->rdev = obj->oo_attr.la_rdev = la->la_rdev;
1027                 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_RDEV(uos), NULL,
1028                                  &osa->rdev, 8);
1029         }
1030         if (la->la_valid & LA_FLAGS) {
1031                 osa->flags = attrs_fs2zfs(la->la_flags);
1032                 /* many flags are not supported by zfs, so ensure a good cached
1033                  * copy */
1034                 obj->oo_attr.la_flags = attrs_zfs2fs(osa->flags);
1035                 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(uos), NULL,
1036                                  &osa->flags, 8);
1037         }
1038         if (la->la_valid & LA_UID) {
1039                 osa->uid = obj->oo_attr.la_uid = la->la_uid;
1040                 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_UID(uos), NULL,
1041                                  &osa->uid, 8);
1042         }
1043         if (la->la_valid & LA_GID) {
1044                 osa->gid = obj->oo_attr.la_gid = la->la_gid;
1045                 SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_GID(uos), NULL,
1046                                  &osa->gid, 8);
1047         }
1048         obj->oo_attr.la_valid |= la->la_valid;
1049         write_unlock(&obj->oo_attr_lock);
1050
1051         rc = osd_object_sa_bulk_update(obj, bulk, cnt, oh);
1052
1053         OBD_FREE(bulk, sizeof(sa_bulk_attr_t) * 10);
1054         RETURN(rc);
1055 }
1056
1057 /*
1058  * Object creation.
1059  *
1060  * XXX temporary solution.
1061  */
1062
1063 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1064                         struct dt_object *parent, struct dt_object *child,
1065                         cfs_umode_t child_mode)
1066 {
1067         LASSERT(ah);
1068
1069         memset(ah, 0, sizeof(*ah));
1070         ah->dah_parent = parent;
1071         ah->dah_mode = child_mode;
1072 }
1073
1074 static int osd_declare_object_create(const struct lu_env *env,
1075                                      struct dt_object *dt,
1076                                      struct lu_attr *attr,
1077                                      struct dt_allocation_hint *hint,
1078                                      struct dt_object_format *dof,
1079                                      struct thandle *handle)
1080 {
1081         char                    *buf = osd_oti_get(env)->oti_str;
1082         const struct lu_fid     *fid = lu_object_fid(&dt->do_lu);
1083         struct osd_object       *obj = osd_dt_obj(dt);
1084         struct osd_device       *osd = osd_obj2dev(obj);
1085         struct osd_thandle      *oh;
1086         uint64_t                 zapid;
1087         int                      rc;
1088         ENTRY;
1089
1090         LASSERT(dof);
1091
1092         switch (dof->dof_type) {
1093                 case DFT_REGULAR:
1094                 case DFT_SYM:
1095                 case DFT_NODE:
1096                         if (obj->oo_dt.do_body_ops == NULL)
1097                                 obj->oo_dt.do_body_ops = &osd_body_ops;
1098                         break;
1099                 default:
1100                         break;
1101         }
1102
1103         LASSERT(handle != NULL);
1104         oh = container_of0(handle, struct osd_thandle, ot_super);
1105         LASSERT(oh->ot_tx != NULL);
1106
1107         switch (dof->dof_type) {
1108                 case DFT_DIR:
1109                 case DFT_INDEX:
1110                         /* for zap create */
1111                         dmu_tx_hold_zap(oh->ot_tx, DMU_NEW_OBJECT, 1, NULL);
1112                         break;
1113                 case DFT_REGULAR:
1114                 case DFT_SYM:
1115                 case DFT_NODE:
1116                         /* first, we'll create new object */
1117                         dmu_tx_hold_bonus(oh->ot_tx, DMU_NEW_OBJECT);
1118                         break;
1119
1120                 default:
1121                         LBUG();
1122                         break;
1123         }
1124
1125         /* and we'll add it to some mapping */
1126         zapid = osd_get_name_n_idx(env, osd, fid, buf);
1127         dmu_tx_hold_bonus(oh->ot_tx, zapid);
1128         dmu_tx_hold_zap(oh->ot_tx, zapid, TRUE, buf);
1129
1130         /* we will also update inode accounting ZAPs */
1131         dmu_tx_hold_bonus(oh->ot_tx, osd->od_iusr_oid);
1132         dmu_tx_hold_zap(oh->ot_tx, osd->od_iusr_oid, TRUE, buf);
1133         dmu_tx_hold_bonus(oh->ot_tx, osd->od_igrp_oid);
1134         dmu_tx_hold_zap(oh->ot_tx, osd->od_igrp_oid, TRUE, buf);
1135
1136         dmu_tx_hold_sa_create(oh->ot_tx, ZFS_SA_BASE_ATTR_SIZE);
1137
1138         __osd_xattr_declare_set(env, obj, sizeof(struct lustre_mdt_attrs),
1139                                 XATTR_NAME_LMA, oh);
1140
1141         rc = osd_declare_quota(env, osd, attr->la_uid, attr->la_gid, 1, oh,
1142                                false, NULL, false);
1143         RETURN(rc);
1144 }
1145
1146 int __osd_attr_init(const struct lu_env *env, udmu_objset_t *uos, uint64_t oid,
1147                     dmu_tx_t *tx, struct lu_attr *la, uint64_t parent)
1148 {
1149         sa_bulk_attr_t  *bulk;
1150         sa_handle_t     *sa_hdl;
1151         struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
1152         uint64_t         gen;
1153         uint64_t         crtime[2];
1154         timestruc_t      now;
1155         int              cnt;
1156         int              rc;
1157
1158         gethrestime(&now);
1159         gen = dmu_tx_get_txg(tx);
1160
1161         ZFS_TIME_ENCODE(&now, crtime);
1162
1163         osa->atime[0] = la->la_atime;
1164         osa->ctime[0] = la->la_ctime;
1165         osa->mtime[0] = la->la_mtime;
1166         osa->mode = la->la_mode;
1167         osa->uid = la->la_uid;
1168         osa->gid = la->la_gid;
1169         osa->rdev = la->la_rdev;
1170         osa->nlink = la->la_nlink;
1171         osa->flags = attrs_fs2zfs(la->la_flags);
1172         osa->size  = la->la_size;
1173
1174         /* Now add in all of the "SA" attributes */
1175         rc = -sa_handle_get(uos->os, oid, NULL, SA_HDL_PRIVATE, &sa_hdl);
1176         if (rc)
1177                 return rc;
1178
1179         OBD_ALLOC(bulk, sizeof(sa_bulk_attr_t) * 13);
1180         if (bulk == NULL) {
1181                 rc = -ENOMEM;
1182                 goto out;
1183         }
1184         /*
1185          * we need to create all SA below upon object create.
1186          *
1187          * XXX The attribute order matters since the accounting callback relies
1188          * on static offsets (i.e. SA_*_OFFSET, see zfs_space_delta_cb()) to
1189          * look up the UID/GID attributes. Moreover, the callback does not seem
1190          * to support the spill block.
1191          * We define attributes in the same order as SA_*_OFFSET in order to
1192          * work around the problem. See ORI-610.
1193          */
1194         cnt = 0;
1195         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(uos), NULL, &osa->mode, 8);
1196         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_SIZE(uos), NULL, &osa->size, 8);
1197         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_GEN(uos), NULL, &gen, 8);
1198         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_UID(uos), NULL, &osa->uid, 8);
1199         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_GID(uos), NULL, &osa->gid, 8);
1200         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_PARENT(uos), NULL, &parent, 8);
1201         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(uos), NULL, &osa->flags, 8);
1202         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(uos), NULL, osa->atime, 16);
1203         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(uos), NULL, osa->mtime, 16);
1204         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(uos), NULL, osa->ctime, 16);
1205         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CRTIME(uos), NULL, crtime, 16);
1206         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(uos), NULL, &osa->nlink, 8);
1207         SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_RDEV(uos), NULL, &osa->rdev, 8);
1208
1209         rc = -sa_replace_all_by_template(sa_hdl, bulk, cnt, tx);
1210
1211         OBD_FREE(bulk, sizeof(sa_bulk_attr_t) * 13);
1212 out:
1213         sa_handle_destroy(sa_hdl);
1214         return rc;
1215 }
1216
1217 /*
1218  * The transaction passed to this routine must have
1219  * dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT) called and then assigned
1220  * to a transaction group.
1221  */
1222 int __osd_object_create(const struct lu_env *env, udmu_objset_t *uos,
1223                         dmu_buf_t **dbp, dmu_tx_t *tx, struct lu_attr *la,
1224                         uint64_t parent, void *tag)
1225 {
1226         uint64_t oid;
1227         int      rc;
1228
1229         LASSERT(tag);
1230         spin_lock(&uos->lock);
1231         uos->objects++;
1232         spin_unlock(&uos->lock);
1233
1234         /* Assert that the transaction has been assigned to a
1235            transaction group. */
1236         LASSERT(tx->tx_txg != 0);
1237
1238         /* Create a new DMU object. */
1239         oid = dmu_object_alloc(uos->os, DMU_OT_PLAIN_FILE_CONTENTS, 0,
1240                                DMU_OT_SA, DN_MAX_BONUSLEN, tx);
1241         rc = -sa_buf_hold(uos->os, oid, tag, dbp);
1242         if (rc)
1243                 return rc;
1244
1245         LASSERT(la->la_valid & LA_MODE);
1246         la->la_size = 0;
1247         la->la_nlink = 1;
1248
1249         return __osd_attr_init(env, uos, oid, tx, la, parent);
1250 }
1251
1252 /*
1253  * The transaction passed to this routine must have
1254  * dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, ...) called and then assigned
1255  * to a transaction group.
1256  *
1257  * Using ZAP_FLAG_HASH64 will force the ZAP to always be a FAT ZAP.
1258  * This is fine for directories today, because storing the FID in the dirent
1259  * will also require a FAT ZAP.  If there is a new type of micro ZAP created
1260  * then we might need to re-evaluate the use of this flag and instead do
1261  * a conversion from the different internal ZAP hash formats being used. */
1262 int __osd_zap_create(const struct lu_env *env, udmu_objset_t *uos,
1263                      dmu_buf_t **zap_dbp, dmu_tx_t *tx,
1264                      struct lu_attr *la, uint64_t parent,
1265                      void *tag, zap_flags_t flags)
1266 {
1267         uint64_t oid;
1268         int      rc;
1269
1270         LASSERT(tag);
1271
1272         spin_lock(&uos->lock);
1273         uos->objects++;
1274         spin_unlock(&uos->lock);
1275
1276         /* Assert that the transaction has been assigned to a
1277            transaction group. */
1278         LASSERT(tx->tx_txg != 0);
1279
1280         oid = zap_create_flags(uos->os, 0, flags | ZAP_FLAG_HASH64,
1281                                DMU_OT_DIRECTORY_CONTENTS, 12, 12,
1282                                DMU_OT_SA, DN_MAX_BONUSLEN, tx);
1283
1284         rc = -sa_buf_hold(uos->os, oid, tag, zap_dbp);
1285         if (rc)
1286                 return rc;
1287
1288         LASSERT(la->la_valid & LA_MODE);
1289         la->la_size = 2;
1290         la->la_nlink = 1;
1291
1292         return __osd_attr_init(env, uos, oid, tx, la, parent);
1293 }
1294
1295 static dmu_buf_t *osd_mkidx(const struct lu_env *env, struct osd_device *osd,
1296                             struct lu_attr *la, uint64_t parent,
1297                             struct osd_thandle *oh)
1298 {
1299         dmu_buf_t *db;
1300         int        rc;
1301
1302         /* Index file should be created as regular file in order not to confuse
1303          * ZPL which could interpret them as directory.
1304          * We set ZAP_FLAG_UINT64_KEY to let ZFS know than we are going to use
1305          * binary keys */
1306         LASSERT(S_ISREG(la->la_mode));
1307         rc = __osd_zap_create(env, &osd->od_objset, &db, oh->ot_tx, la,
1308                               parent, osd_obj_tag, ZAP_FLAG_UINT64_KEY);
1309         if (rc)
1310                 return ERR_PTR(rc);
1311         return db;
1312 }
1313
1314 static dmu_buf_t *osd_mkdir(const struct lu_env *env, struct osd_device *osd,
1315                             struct lu_attr *la, uint64_t parent,
1316                             struct osd_thandle *oh)
1317 {
1318         dmu_buf_t *db;
1319         int        rc;
1320
1321         LASSERT(S_ISDIR(la->la_mode));
1322         rc = __osd_zap_create(env, &osd->od_objset, &db, oh->ot_tx, la,
1323                               parent, osd_obj_tag, 0);
1324         if (rc)
1325                 return ERR_PTR(rc);
1326         return db;
1327 }
1328
1329 static dmu_buf_t* osd_mkreg(const struct lu_env *env, struct osd_device *osd,
1330                             struct lu_attr *la, uint64_t parent,
1331                             struct osd_thandle *oh)
1332 {
1333         dmu_buf_t *db;
1334         int         rc;
1335
1336         LASSERT(S_ISREG(la->la_mode));
1337         rc = __osd_object_create(env, &osd->od_objset, &db, oh->ot_tx, la,
1338                                  parent, osd_obj_tag);
1339         if (rc)
1340                 return ERR_PTR(rc);
1341
1342         /*
1343          * XXX: a hack, OST to use bigger blocksize. we need
1344          * a method in OSD API to control this from OFD/MDD
1345          */
1346         if (!lu_device_is_md(osd2lu_dev(osd))) {
1347                 rc = -dmu_object_set_blocksize(osd->od_objset.os,
1348                                                db->db_object,
1349                                 128 << 10, 0, oh->ot_tx);
1350                 if (unlikely(rc)) {
1351                         CERROR("%s: can't change blocksize: %d\n",
1352                                osd->od_svname, rc);
1353                         return ERR_PTR(rc);
1354                 }
1355         }
1356
1357         return db;
1358 }
1359
1360 static dmu_buf_t *osd_mksym(const struct lu_env *env, struct osd_device *osd,
1361                             struct lu_attr *la, uint64_t parent,
1362                             struct osd_thandle *oh)
1363 {
1364         dmu_buf_t *db;
1365         int        rc;
1366
1367         LASSERT(S_ISLNK(la->la_mode));
1368         rc = __osd_object_create(env, &osd->od_objset, &db, oh->ot_tx, la,
1369                                  parent, osd_obj_tag);
1370         if (rc)
1371                 return ERR_PTR(rc);
1372         return db;
1373 }
1374
1375 static dmu_buf_t *osd_mknod(const struct lu_env *env, struct osd_device *osd,
1376                             struct lu_attr *la, uint64_t parent,
1377                             struct osd_thandle *oh)
1378 {
1379         dmu_buf_t *db;
1380         int        rc;
1381
1382         la->la_valid = LA_MODE;
1383         if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode))
1384                 la->la_valid |= LA_RDEV;
1385
1386         rc = __osd_object_create(env, &osd->od_objset, &db, oh->ot_tx, la,
1387                                  parent, osd_obj_tag);
1388         if (rc)
1389                 return ERR_PTR(rc);
1390         return db;
1391 }
1392
1393 typedef dmu_buf_t *(*osd_obj_type_f)(const struct lu_env *env,
1394                                      struct osd_device *osd,
1395                                      struct lu_attr *la,
1396                                      uint64_t parent,
1397                                      struct osd_thandle *oh);
1398
1399 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
1400 {
1401         osd_obj_type_f result;
1402
1403         switch (type) {
1404         case DFT_DIR:
1405                 result = osd_mkdir;
1406                 break;
1407         case DFT_INDEX:
1408                 result = osd_mkidx;
1409                 break;
1410         case DFT_REGULAR:
1411                 result = osd_mkreg;
1412                 break;
1413         case DFT_SYM:
1414                 result = osd_mksym;
1415                 break;
1416         case DFT_NODE:
1417                 result = osd_mknod;
1418                 break;
1419         default:
1420                 LBUG();
1421                 break;
1422         }
1423         return result;
1424 }
1425
1426 /*
1427  * Primitives for directory (i.e. ZAP) handling
1428  */
1429 static inline int osd_init_lma(const struct lu_env *env, struct osd_object *obj,
1430                                const struct lu_fid *fid, struct osd_thandle *oh)
1431 {
1432         struct osd_thread_info  *info = osd_oti_get(env);
1433         struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
1434         struct lu_buf            buf;
1435         int rc;
1436
1437         lustre_lma_init(lma, fid, 0);
1438         lustre_lma_swab(lma);
1439         buf.lb_buf = lma;
1440         buf.lb_len = sizeof(*lma);
1441
1442         rc = osd_xattr_set_internal(env, obj, &buf, XATTR_NAME_LMA,
1443                                     LU_XATTR_CREATE, oh, BYPASS_CAPA);
1444
1445         return rc;
1446 }
1447
1448 /*
1449  * Concurrency: @dt is write locked.
1450  */
1451 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1452                              struct lu_attr *attr,
1453                              struct dt_allocation_hint *hint,
1454                              struct dt_object_format *dof,
1455                              struct thandle *th)
1456 {
1457         struct zpl_direntry     *zde = &osd_oti_get(env)->oti_zde.lzd_reg;
1458         const struct lu_fid     *fid = lu_object_fid(&dt->do_lu);
1459         struct osd_object       *obj = osd_dt_obj(dt);
1460         struct osd_device       *osd = osd_obj2dev(obj);
1461         char                    *buf = osd_oti_get(env)->oti_str;
1462         struct osd_thandle      *oh;
1463         dmu_buf_t               *db;
1464         uint64_t                 zapid;
1465         int                      rc;
1466
1467         ENTRY;
1468
1469         /* concurrent create declarations should not see
1470          * the object inconsistent (db, attr, etc).
1471          * in regular cases acquisition should be cheap */
1472         down(&obj->oo_guard);
1473
1474         LASSERT(osd_invariant(obj));
1475         LASSERT(!dt_object_exists(dt));
1476         LASSERT(dof != NULL);
1477
1478         LASSERT(th != NULL);
1479         oh = container_of0(th, struct osd_thandle, ot_super);
1480
1481         /*
1482          * XXX missing: Quote handling.
1483          */
1484
1485         LASSERT(obj->oo_db == NULL);
1486
1487         /* to follow ZFS on-disk format we need
1488          * to initialize parent dnode properly */
1489         zapid = 0;
1490         if (hint && hint->dah_parent)
1491                 zapid = osd_dt_obj(hint->dah_parent)->oo_db->db_object;
1492
1493         db = osd_create_type_f(dof->dof_type)(env, osd, attr, zapid, oh);
1494         if (IS_ERR(db))
1495                 GOTO(out, rc = PTR_ERR(th));
1496
1497         zde->zde_pad = 0;
1498         zde->zde_dnode = db->db_object;
1499         zde->zde_type = IFTODT(attr->la_mode & S_IFMT);
1500
1501         zapid = osd_get_name_n_idx(env, osd, fid, buf);
1502
1503         rc = -zap_add(osd->od_objset.os, zapid, buf, 8, 1, zde, oh->ot_tx);
1504         if (rc)
1505                 GOTO(out, rc);
1506
1507         /* Add new object to inode accounting.
1508          * Errors are not considered as fatal */
1509         rc = -zap_increment_int(osd->od_objset.os, osd->od_iusr_oid,
1510                                 (attr->la_valid & LA_UID) ? attr->la_uid : 0, 1,
1511                                 oh->ot_tx);
1512         if (rc)
1513                 CERROR("%s: failed to add "DFID" to accounting ZAP for usr %d "
1514                         "(%d)\n", osd->od_svname, PFID(fid), attr->la_uid, rc);
1515         rc = -zap_increment_int(osd->od_objset.os, osd->od_igrp_oid,
1516                                 (attr->la_valid & LA_GID) ? attr->la_gid : 0, 1,
1517                                 oh->ot_tx);
1518         if (rc)
1519                 CERROR("%s: failed to add "DFID" to accounting ZAP for grp %d "
1520                         "(%d)\n", osd->od_svname, PFID(fid), attr->la_gid, rc);
1521
1522         /* configure new osd object */
1523         obj->oo_db = db;
1524         rc = osd_object_init0(env, obj);
1525         LASSERT(ergo(rc == 0, dt_object_exists(dt)));
1526         LASSERT(osd_invariant(obj));
1527
1528         rc = osd_init_lma(env, obj, fid, oh);
1529         if (rc) {
1530                 CERROR("%s: can not set LMA on "DFID": rc = %d\n",
1531                        osd->od_svname, PFID(fid), rc);
1532                 /* ignore errors during LMA initialization */
1533                 rc = 0;
1534         }
1535
1536 out:
1537         up(&obj->oo_guard);
1538         RETURN(rc);
1539 }
1540
1541 static int osd_declare_object_ref_add(const struct lu_env *env,
1542                                       struct dt_object *dt,
1543                                       struct thandle *th)
1544 {
1545         return osd_declare_attr_set(env, dt, NULL, th);
1546 }
1547
1548 /*
1549  * Concurrency: @dt is write locked.
1550  */
1551 static int osd_object_ref_add(const struct lu_env *env,
1552                               struct dt_object *dt,
1553                               struct thandle *handle)
1554 {
1555         struct osd_object       *obj = osd_dt_obj(dt);
1556         struct osd_thandle      *oh;
1557         struct osd_device       *osd = osd_obj2dev(obj);
1558         udmu_objset_t           *uos = &osd->od_objset;
1559         uint64_t                 nlink;
1560         int rc;
1561
1562         ENTRY;
1563
1564         LASSERT(osd_invariant(obj));
1565         LASSERT(dt_object_exists(dt));
1566         LASSERT(obj->oo_sa_hdl != NULL);
1567
1568         oh = container_of0(handle, struct osd_thandle, ot_super);
1569
1570         write_lock(&obj->oo_attr_lock);
1571         nlink = ++obj->oo_attr.la_nlink;
1572         write_unlock(&obj->oo_attr_lock);
1573
1574         rc = osd_object_sa_update(obj, SA_ZPL_LINKS(uos), &nlink, 8, oh);
1575         return rc;
1576 }
1577
1578 static int osd_declare_object_ref_del(const struct lu_env *env,
1579                                       struct dt_object *dt,
1580                                       struct thandle *handle)
1581 {
1582         return osd_declare_attr_set(env, dt, NULL, handle);
1583 }
1584
1585 /*
1586  * Concurrency: @dt is write locked.
1587  */
1588 static int osd_object_ref_del(const struct lu_env *env,
1589                               struct dt_object *dt,
1590                               struct thandle *handle)
1591 {
1592         struct osd_object       *obj = osd_dt_obj(dt);
1593         struct osd_thandle      *oh;
1594         struct osd_device       *osd = osd_obj2dev(obj);
1595         udmu_objset_t           *uos = &osd->od_objset;
1596         uint64_t                 nlink;
1597         int                      rc;
1598
1599         ENTRY;
1600
1601         LASSERT(osd_invariant(obj));
1602         LASSERT(dt_object_exists(dt));
1603         LASSERT(obj->oo_sa_hdl != NULL);
1604
1605         oh = container_of0(handle, struct osd_thandle, ot_super);
1606         LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
1607
1608         write_lock(&obj->oo_attr_lock);
1609         nlink = --obj->oo_attr.la_nlink;
1610         write_unlock(&obj->oo_attr_lock);
1611
1612         rc = osd_object_sa_update(obj, SA_ZPL_LINKS(uos), &nlink, 8, oh);
1613         return rc;
1614 }
1615
1616 static int capa_is_sane(const struct lu_env *env, struct osd_device *dev,
1617                         struct lustre_capa *capa, struct lustre_capa_key *keys)
1618 {
1619         struct osd_thread_info  *oti = osd_oti_get(env);
1620         struct obd_capa         *oc;
1621         int                      i, rc = 0;
1622         ENTRY;
1623
1624         oc = capa_lookup(dev->od_capa_hash, capa, 0);
1625         if (oc) {
1626                 if (capa_is_expired(oc)) {
1627                         DEBUG_CAPA(D_ERROR, capa, "expired");
1628                         rc = -ESTALE;
1629                 }
1630                 capa_put(oc);
1631                 RETURN(rc);
1632         }
1633
1634         spin_lock(&capa_lock);
1635         for (i = 0; i < 2; i++) {
1636                 if (keys[i].lk_keyid == capa->lc_keyid) {
1637                         oti->oti_capa_key = keys[i];
1638                         break;
1639                 }
1640         }
1641         spin_unlock(&capa_lock);
1642
1643         if (i == 2) {
1644                 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
1645                 RETURN(-ESTALE);
1646         }
1647
1648         rc = capa_hmac(oti->oti_capa.lc_hmac, capa, oti->oti_capa_key.lk_key);
1649         if (rc)
1650                 RETURN(rc);
1651         if (memcmp(oti->oti_capa.lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac)))
1652         {
1653                 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
1654                 RETURN(-EACCES);
1655         }
1656
1657         oc = capa_add(dev->od_capa_hash, capa);
1658         capa_put(oc);
1659
1660         RETURN(0);
1661 }
1662
1663 static int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
1664                            struct lustre_capa *capa, __u64 opc)
1665 {
1666         const struct lu_fid     *fid = lu_object_fid(&dt->do_lu);
1667         struct osd_device       *dev = osd_dev(dt->do_lu.lo_dev);
1668         int                      rc;
1669
1670         if (!dev->od_fl_capa)
1671                 return 0;
1672
1673         if (capa == BYPASS_CAPA)
1674                 return 0;
1675
1676         if (!capa) {
1677                 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
1678                 return -EACCES;
1679         }
1680
1681         if (!lu_fid_eq(fid, &capa->lc_fid)) {
1682                 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",PFID(fid));
1683                 return -EACCES;
1684         }
1685
1686         if (!capa_opc_supported(capa, opc)) {
1687                 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
1688                 return -EACCES;
1689         }
1690
1691         if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
1692                 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
1693                 return -EACCES;
1694         }
1695
1696         return 0;
1697 }
1698
1699 static struct obd_capa *osd_capa_get(const struct lu_env *env,
1700                                      struct dt_object *dt,
1701                                      struct lustre_capa *old,
1702                                      __u64 opc)
1703 {
1704         struct osd_thread_info  *info = osd_oti_get(env);
1705         const struct lu_fid     *fid = lu_object_fid(&dt->do_lu);
1706         struct osd_object       *obj = osd_dt_obj(dt);
1707         struct osd_device       *dev = osd_obj2dev(obj);
1708         struct lustre_capa_key  *key = &info->oti_capa_key;
1709         struct lustre_capa      *capa = &info->oti_capa;
1710         struct obd_capa         *oc;
1711         int                      rc;
1712         ENTRY;
1713
1714         if (!dev->od_fl_capa)
1715                 RETURN(ERR_PTR(-ENOENT));
1716
1717         LASSERT(dt_object_exists(dt));
1718         LASSERT(osd_invariant(obj));
1719
1720         /* renewal sanity check */
1721         if (old && osd_object_auth(env, dt, old, opc))
1722                 RETURN(ERR_PTR(-EACCES));
1723
1724         capa->lc_fid = *fid;
1725         capa->lc_opc = opc;
1726         capa->lc_uid = 0;
1727         capa->lc_flags = dev->od_capa_alg << 24;
1728         capa->lc_timeout = dev->od_capa_timeout;
1729         capa->lc_expiry = 0;
1730
1731         oc = capa_lookup(dev->od_capa_hash, capa, 1);
1732         if (oc) {
1733                 LASSERT(!capa_is_expired(oc));
1734                 RETURN(oc);
1735         }
1736
1737         spin_lock(&capa_lock);
1738         *key = dev->od_capa_keys[1];
1739         spin_unlock(&capa_lock);
1740
1741         capa->lc_keyid = key->lk_keyid;
1742         capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
1743
1744         rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
1745         if (rc) {
1746                 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
1747                 LBUG();
1748                 RETURN(ERR_PTR(rc));
1749         }
1750
1751         oc = capa_add(dev->od_capa_hash, capa);
1752         RETURN(oc);
1753 }
1754
1755 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
1756 {
1757         struct osd_device *osd = osd_obj2dev(osd_dt_obj(dt));
1758         ENTRY;
1759
1760         /* XXX: no other option than syncing the whole filesystem until we
1761          * support ZIL */
1762         txg_wait_synced(dmu_objset_pool(osd->od_objset.os), 0ULL);
1763
1764         RETURN(0);
1765 }
1766
1767 static struct dt_object_operations osd_obj_ops = {
1768         .do_read_lock           = osd_object_read_lock,
1769         .do_write_lock          = osd_object_write_lock,
1770         .do_read_unlock         = osd_object_read_unlock,
1771         .do_write_unlock        = osd_object_write_unlock,
1772         .do_write_locked        = osd_object_write_locked,
1773         .do_attr_get            = osd_attr_get,
1774         .do_declare_attr_set    = osd_declare_attr_set,
1775         .do_attr_set            = osd_attr_set,
1776         .do_ah_init             = osd_ah_init,
1777         .do_declare_create      = osd_declare_object_create,
1778         .do_create              = osd_object_create,
1779         .do_declare_destroy     = osd_declare_object_destroy,
1780         .do_destroy             = osd_object_destroy,
1781         .do_index_try           = osd_index_try,
1782         .do_declare_ref_add     = osd_declare_object_ref_add,
1783         .do_ref_add             = osd_object_ref_add,
1784         .do_declare_ref_del     = osd_declare_object_ref_del,
1785         .do_ref_del             = osd_object_ref_del,
1786         .do_xattr_get           = osd_xattr_get,
1787         .do_declare_xattr_set   = osd_declare_xattr_set,
1788         .do_xattr_set           = osd_xattr_set,
1789         .do_declare_xattr_del   = osd_declare_xattr_del,
1790         .do_xattr_del           = osd_xattr_del,
1791         .do_xattr_list          = osd_xattr_list,
1792         .do_capa_get            = osd_capa_get,
1793         .do_object_sync         = osd_object_sync,
1794 };
1795
1796 static struct lu_object_operations osd_lu_obj_ops = {
1797         .loo_object_init        = osd_object_init,
1798         .loo_object_delete      = osd_object_delete,
1799         .loo_object_release     = osd_object_release,
1800         .loo_object_free        = osd_object_free,
1801         .loo_object_print       = osd_object_print,
1802         .loo_object_invariant   = osd_object_invariant,
1803 };
1804
1805 static int osd_otable_it_attr_get(const struct lu_env *env,
1806                                 struct dt_object *dt,
1807                                 struct lu_attr *attr,
1808                                 struct lustre_capa *capa)
1809 {
1810         attr->la_valid = 0;
1811         return 0;
1812 }
1813
1814 static struct dt_object_operations osd_obj_otable_it_ops = {
1815         .do_attr_get    = osd_otable_it_attr_get,
1816         .do_index_try   = osd_index_try,
1817 };
1818