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