4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/dt_object.c
39 * Generic functions from dt_object.h
41 * Author: Nikita Danilov <nikita@clusterfs.com>
44 #define DEBUG_SUBSYSTEM S_CLASS
47 #include <dt_object.h>
48 #include <libcfs/list.h>
50 #include <lustre_fid.h>
52 #include <lustre_quota.h>
54 /* context key constructor/destructor: dt_global_key_init, dt_global_key_fini */
55 LU_KEY_INIT(dt_global, struct dt_thread_info);
56 LU_KEY_FINI(dt_global, struct dt_thread_info);
58 struct lu_context_key dt_key = {
59 .lct_tags = LCT_MD_THREAD | LCT_DT_THREAD | LCT_MG_THREAD | LCT_LOCAL,
60 .lct_init = dt_global_key_init,
61 .lct_fini = dt_global_key_fini
63 EXPORT_SYMBOL(dt_key);
65 /* no lock is necessary to protect the list, because call-backs
66 * are added during system startup. Please refer to "struct dt_device".
68 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb)
70 cfs_list_add(&cb->dtc_linkage, &dev->dd_txn_callbacks);
72 EXPORT_SYMBOL(dt_txn_callback_add);
74 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb)
76 cfs_list_del_init(&cb->dtc_linkage);
78 EXPORT_SYMBOL(dt_txn_callback_del);
80 int dt_txn_hook_start(const struct lu_env *env,
81 struct dt_device *dev, struct thandle *th)
84 struct dt_txn_callback *cb;
89 cfs_list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
90 if (cb->dtc_txn_start == NULL ||
91 !(cb->dtc_tag & env->le_ctx.lc_tags))
93 rc = cb->dtc_txn_start(env, th, cb->dtc_cookie);
99 EXPORT_SYMBOL(dt_txn_hook_start);
101 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn)
103 struct dt_device *dev = txn->th_dev;
104 struct dt_txn_callback *cb;
110 cfs_list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
111 if (cb->dtc_txn_stop == NULL ||
112 !(cb->dtc_tag & env->le_ctx.lc_tags))
114 rc = cb->dtc_txn_stop(env, txn, cb->dtc_cookie);
120 EXPORT_SYMBOL(dt_txn_hook_stop);
122 void dt_txn_hook_commit(struct thandle *txn)
124 struct dt_txn_callback *cb;
129 cfs_list_for_each_entry(cb, &txn->th_dev->dd_txn_callbacks,
131 if (cb->dtc_txn_commit)
132 cb->dtc_txn_commit(txn, cb->dtc_cookie);
135 EXPORT_SYMBOL(dt_txn_hook_commit);
137 int dt_device_init(struct dt_device *dev, struct lu_device_type *t)
140 CFS_INIT_LIST_HEAD(&dev->dd_txn_callbacks);
141 return lu_device_init(&dev->dd_lu_dev, t);
143 EXPORT_SYMBOL(dt_device_init);
145 void dt_device_fini(struct dt_device *dev)
147 lu_device_fini(&dev->dd_lu_dev);
149 EXPORT_SYMBOL(dt_device_fini);
151 int dt_object_init(struct dt_object *obj,
152 struct lu_object_header *h, struct lu_device *d)
155 return lu_object_init(&obj->do_lu, h, d);
157 EXPORT_SYMBOL(dt_object_init);
159 void dt_object_fini(struct dt_object *obj)
161 lu_object_fini(&obj->do_lu);
163 EXPORT_SYMBOL(dt_object_fini);
165 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj)
167 if (obj->do_index_ops == NULL)
168 obj->do_ops->do_index_try(env, obj, &dt_directory_features);
169 return obj->do_index_ops != NULL;
171 EXPORT_SYMBOL(dt_try_as_dir);
173 enum dt_format_type dt_mode_to_dft(__u32 mode)
175 enum dt_format_type result;
177 switch (mode & S_IFMT) {
182 result = DFT_REGULAR;
199 EXPORT_SYMBOL(dt_mode_to_dft);
202 * lookup fid for object named \a name in directory \a dir.
205 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
206 const char *name, struct lu_fid *fid)
208 if (dt_try_as_dir(env, dir))
209 return dt_lookup(env, dir, (struct dt_rec *)fid,
210 (const struct dt_key *)name, BYPASS_CAPA);
213 EXPORT_SYMBOL(dt_lookup_dir);
215 /* this differs from dt_locate by top_dev as parameter
216 * but not one from lu_site */
217 struct dt_object *dt_locate_at(const struct lu_env *env,
218 struct dt_device *dev,
219 const struct lu_fid *fid,
220 struct lu_device *top_dev,
221 const struct lu_object_conf *conf)
223 struct lu_object *lo;
226 lo = lu_object_find_at(env, top_dev, fid, conf);
228 return ERR_PTR(PTR_ERR(lo));
232 list_for_each_entry(n, &lo->lo_header->loh_layers, lo_linkage) {
233 if (n->lo_dev == &dev->dd_lu_dev)
234 return container_of0(n, struct dt_object, do_lu);
237 return ERR_PTR(-ENOENT);
239 EXPORT_SYMBOL(dt_locate_at);
242 * find a object named \a entry in given \a dfh->dfh_o directory.
244 static int dt_find_entry(const struct lu_env *env, const char *entry, void *data)
246 struct dt_find_hint *dfh = data;
247 struct dt_device *dt = dfh->dfh_dt;
248 struct lu_fid *fid = dfh->dfh_fid;
249 struct dt_object *obj = dfh->dfh_o;
252 result = dt_lookup_dir(env, obj, entry, fid);
253 lu_object_put(env, &obj->do_lu);
255 obj = dt_locate(env, dt, fid);
257 result = PTR_ERR(obj);
264 * Abstract function which parses path name. This function feeds
265 * path component to \a entry_func.
267 int dt_path_parser(const struct lu_env *env,
268 char *path, dt_entry_func_t entry_func,
275 e = strsep(&path, "/");
280 if (!path || path[0] == '\0')
284 rc = entry_func(env, e, data);
293 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
294 const char *path, struct lu_fid *fid)
296 struct dt_thread_info *info = dt_info(env);
297 struct dt_find_hint *dfh = &info->dti_dfh;
298 struct dt_object *obj;
299 char *local = info->dti_buf;
306 strncpy(local, path, DT_MAX_PATH);
307 local[DT_MAX_PATH - 1] = '\0';
309 result = dt->dd_ops->dt_root_get(env, dt, fid);
311 obj = dt_locate(env, dt, fid);
314 result = dt_path_parser(env, local, dt_find_entry, dfh);
316 obj = ERR_PTR(result);
321 obj = ERR_PTR(result);
325 EXPORT_SYMBOL(dt_store_resolve);
327 static struct dt_object *dt_reg_open(const struct lu_env *env,
328 struct dt_device *dt,
336 result = dt_lookup_dir(env, p, name, fid);
338 o = dt_locate(env, dt, fid);
347 * Open dt object named \a filename from \a dirname directory.
348 * \param dt dt device
349 * \param fid on success, object fid is stored in *fid
351 struct dt_object *dt_store_open(const struct lu_env *env,
352 struct dt_device *dt,
354 const char *filename,
357 struct dt_object *file;
358 struct dt_object *dir;
360 dir = dt_store_resolve(env, dt, dirname, fid);
362 file = dt_reg_open(env, dt, dir,
364 lu_object_put(env, &dir->do_lu);
370 EXPORT_SYMBOL(dt_store_open);
372 struct dt_object *dt_find_or_create(const struct lu_env *env,
373 struct dt_device *dt,
374 const struct lu_fid *fid,
375 struct dt_object_format *dof,
378 struct dt_object *dto;
384 dto = dt_locate(env, dt, fid);
388 LASSERT(dto != NULL);
389 if (dt_object_exists(dto))
392 th = dt_trans_create(env, dt);
394 GOTO(out, rc = PTR_ERR(th));
396 rc = dt_declare_create(env, dto, at, NULL, dof, th);
398 GOTO(trans_stop, rc);
400 rc = dt_trans_start_local(env, dt, th);
402 GOTO(trans_stop, rc);
404 dt_write_lock(env, dto, 0);
405 if (dt_object_exists(dto))
406 GOTO(unlock, rc = 0);
408 CDEBUG(D_OTHER, "create new object "DFID"\n", PFID(fid));
410 rc = dt_create(env, dto, at, NULL, dof, th);
413 LASSERT(dt_object_exists(dto));
415 dt_write_unlock(env, dto);
417 dt_trans_stop(env, dt, th);
420 lu_object_put(env, &dto->do_lu);
425 EXPORT_SYMBOL(dt_find_or_create);
427 /* dt class init function. */
428 int dt_global_init(void)
432 LU_CONTEXT_KEY_INIT(&dt_key);
433 result = lu_context_key_register(&dt_key);
437 void dt_global_fini(void)
439 lu_context_key_degister(&dt_key);
443 * Generic read helper. May return an error for partial reads.
445 * \param env lustre environment
446 * \param dt object to be read
447 * \param buf lu_buf to be filled, with buffer pointer and length
448 * \param pos position to start reading, updated as data is read
450 * \retval real size of data read
451 * \retval -ve errno on failure
453 int dt_read(const struct lu_env *env, struct dt_object *dt,
454 struct lu_buf *buf, loff_t *pos)
456 LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
457 return dt->do_body_ops->dbo_read(env, dt, buf, pos, BYPASS_CAPA);
459 EXPORT_SYMBOL(dt_read);
462 * Read structures of fixed size from storage. Unlike dt_read(), using
463 * dt_record_read() will return an error for partial reads.
465 * \param env lustre environment
466 * \param dt object to be read
467 * \param buf lu_buf to be filled, with buffer pointer and length
468 * \param pos position to start reading, updated as data is read
470 * \retval 0 on successfully reading full buffer
471 * \retval -EFAULT on short read
472 * \retval -ve errno on failure
474 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
475 struct lu_buf *buf, loff_t *pos)
479 LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
481 rc = dt->do_body_ops->dbo_read(env, dt, buf, pos, BYPASS_CAPA);
483 if (rc == buf->lb_len)
489 EXPORT_SYMBOL(dt_record_read);
491 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
492 const struct lu_buf *buf, loff_t *pos, struct thandle *th)
496 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
498 LASSERT(dt->do_body_ops);
499 LASSERT(dt->do_body_ops->dbo_write);
500 rc = dt->do_body_ops->dbo_write(env, dt, buf, pos, th, BYPASS_CAPA, 1);
501 if (rc == buf->lb_len)
507 EXPORT_SYMBOL(dt_record_write);
509 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
513 char *xname = XATTR_NAME_VERSION;
517 vbuf.lb_len = sizeof(dt_obj_version_t);
518 return dt_declare_xattr_set(env, o, &vbuf, xname, 0, th);
521 EXPORT_SYMBOL(dt_declare_version_set);
523 void dt_version_set(const struct lu_env *env, struct dt_object *o,
524 dt_obj_version_t version, struct thandle *th)
527 char *xname = XATTR_NAME_VERSION;
531 vbuf.lb_buf = &version;
532 vbuf.lb_len = sizeof(version);
534 rc = dt_xattr_set(env, o, &vbuf, xname, 0, th, BYPASS_CAPA);
536 CDEBUG(D_INODE, "Can't set version, rc %d\n", rc);
539 EXPORT_SYMBOL(dt_version_set);
541 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o)
544 char *xname = XATTR_NAME_VERSION;
545 dt_obj_version_t version;
549 vbuf.lb_buf = &version;
550 vbuf.lb_len = sizeof(version);
551 rc = dt_xattr_get(env, o, &vbuf, xname, BYPASS_CAPA);
552 if (rc != sizeof(version)) {
553 CDEBUG(D_INODE, "Can't get version, rc %d\n", rc);
558 EXPORT_SYMBOL(dt_version_get);
560 /* list of all supported index types */
563 const struct dt_index_features dt_directory_features;
564 EXPORT_SYMBOL(dt_directory_features);
567 const struct dt_index_features dt_otable_features;
568 EXPORT_SYMBOL(dt_otable_features);
571 const struct dt_index_features dt_lfsck_orphan_features = {
573 .dif_keysize_min = sizeof(struct lu_fid),
574 .dif_keysize_max = sizeof(struct lu_fid),
575 .dif_recsize_min = sizeof(struct lu_orphan_rec),
576 .dif_recsize_max = sizeof(struct lu_orphan_rec),
579 EXPORT_SYMBOL(dt_lfsck_orphan_features);
582 const struct dt_index_features dt_lfsck_features = {
583 .dif_flags = DT_IND_UPDATE,
584 .dif_keysize_min = sizeof(struct lu_fid),
585 .dif_keysize_max = sizeof(struct lu_fid),
586 .dif_recsize_min = sizeof(__u8),
587 .dif_recsize_max = sizeof(__u8),
590 EXPORT_SYMBOL(dt_lfsck_features);
592 /* accounting indexes */
593 const struct dt_index_features dt_acct_features = {
594 .dif_flags = DT_IND_UPDATE,
595 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
596 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
597 .dif_recsize_min = sizeof(struct lquota_acct_rec), /* 16 bytes */
598 .dif_recsize_max = sizeof(struct lquota_acct_rec), /* 16 bytes */
601 EXPORT_SYMBOL(dt_acct_features);
603 /* global quota files */
604 const struct dt_index_features dt_quota_glb_features = {
605 .dif_flags = DT_IND_UPDATE,
606 /* a different key would have to be used for per-directory quota */
607 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
608 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
609 .dif_recsize_min = sizeof(struct lquota_glb_rec), /* 32 bytes */
610 .dif_recsize_max = sizeof(struct lquota_glb_rec), /* 32 bytes */
613 EXPORT_SYMBOL(dt_quota_glb_features);
615 /* slave quota files */
616 const struct dt_index_features dt_quota_slv_features = {
617 .dif_flags = DT_IND_UPDATE,
618 /* a different key would have to be used for per-directory quota */
619 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
620 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
621 .dif_recsize_min = sizeof(struct lquota_slv_rec), /* 8 bytes */
622 .dif_recsize_max = sizeof(struct lquota_slv_rec), /* 8 bytes */
625 EXPORT_SYMBOL(dt_quota_slv_features);
627 /* helper function returning what dt_index_features structure should be used
628 * based on the FID sequence. This is used by OBD_IDX_READ RPC */
629 static inline const struct dt_index_features *dt_index_feat_select(__u64 seq,
632 if (seq == FID_SEQ_QUOTA_GLB) {
633 /* global quota index */
635 /* global quota index should be a regular file */
636 return ERR_PTR(-ENOENT);
637 return &dt_quota_glb_features;
638 } else if (seq == FID_SEQ_QUOTA) {
639 /* quota slave index */
641 /* slave index should be a regular file */
642 return ERR_PTR(-ENOENT);
643 return &dt_quota_slv_features;
644 } else if (seq == FID_SEQ_LAYOUT_RBTREE){
645 return &dt_lfsck_orphan_features;
646 } else if (seq >= FID_SEQ_NORMAL) {
647 /* object is part of the namespace, verify that it is a
650 /* sorry, we can only deal with directory */
651 return ERR_PTR(-ENOTDIR);
652 return &dt_directory_features;
655 return ERR_PTR(-EOPNOTSUPP);
659 * Fill a lu_idxpage with key/record pairs read for transfer via OBD_IDX_READ
662 * \param env - is the environment passed by the caller
663 * \param lp - is a pointer to the lu_page to fill
664 * \param nob - is the maximum number of bytes that should be copied
665 * \param iops - is the index operation vector associated with the index object
666 * \param it - is a pointer to the current iterator
667 * \param attr - is the index attribute to pass to iops->rec()
668 * \param arg - is a pointer to the idx_info structure
670 static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
671 int nob, const struct dt_it_ops *iops,
672 struct dt_it *it, __u32 attr, void *arg)
674 struct idx_info *ii = (struct idx_info *)arg;
675 struct lu_idxpage *lip = &lp->lp_idx;
680 /* initialize the header of the new container */
681 memset(lip, 0, LIP_HDR_SIZE);
682 lip->lip_magic = LIP_MAGIC;
685 /* compute size needed to store a key/record pair */
686 size = ii->ii_recsize + ii->ii_keysize;
687 if ((ii->ii_flags & II_FL_NOHASH) == 0)
688 /* add hash if the client wants it */
689 size += sizeof(__u64);
691 entry = lip->lip_entries;
693 char *tmp_entry = entry;
699 /* fetch 64-bit hash value */
700 hash = iops->store(env, it);
701 ii->ii_hash_end = hash;
703 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_IDX_READ_BREAK)) {
704 if (lip->lip_nr != 0)
709 if (lip->lip_nr == 0)
710 GOTO(out, rc = -EINVAL);
714 if (!(ii->ii_flags & II_FL_NOHASH)) {
715 /* client wants to the 64-bit hash value associated with
717 memcpy(tmp_entry, &hash, sizeof(hash));
718 tmp_entry += sizeof(hash);
721 if (ii->ii_flags & II_FL_VARKEY)
722 keysize = iops->key_size(env, it);
724 keysize = ii->ii_keysize;
726 if (!(ii->ii_flags & II_FL_NOKEY)) {
727 /* then the key value */
728 key = iops->key(env, it);
729 memcpy(tmp_entry, key, keysize);
730 tmp_entry += keysize;
733 /* and finally the record */
734 rc = iops->rec(env, it, (struct dt_rec *)tmp_entry, attr);
739 /* hash/key/record successfully copied! */
741 if (unlikely(lip->lip_nr == 1 && ii->ii_count == 0))
742 ii->ii_hash_start = hash;
744 if (ii->ii_flags & II_FL_VARREC)
745 recsize = iops->rec_size(env, it, attr);
747 recsize = ii->ii_recsize;
749 entry = tmp_entry + recsize;
753 /* move on to the next record */
755 rc = iops->next(env, it);
756 } while (rc == -ESTALE);
762 if (rc >= 0 && lip->lip_nr > 0)
763 /* one more container */
766 /* no more entries */
767 ii->ii_hash_end = II_END_OFF;
773 * Walk index and fill lu_page containers with key/record pairs
775 * \param env - is the environment passed by the caller
776 * \param obj - is the index object to parse
777 * \param rdpg - is the lu_rdpg descriptor associated with the transfer
778 * \param filler - is the callback function responsible for filling a lu_page
779 * with key/record pairs in the format wanted by the caller
780 * \param arg - is an opaq argument passed to the filler function
782 * \retval sum (in bytes) of all filled lu_pages
783 * \retval -ve errno on failure
785 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
786 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
790 const struct dt_it_ops *iops;
791 unsigned int pageidx, nob, nlupgs = 0;
795 LASSERT(rdpg->rp_pages != NULL);
796 LASSERT(obj->do_index_ops != NULL);
798 nob = rdpg->rp_count;
802 /* Iterate through index and fill containers from @rdpg */
803 iops = &obj->do_index_ops->dio_it;
804 LASSERT(iops != NULL);
805 it = iops->init(env, obj, rdpg->rp_attrs, BYPASS_CAPA);
809 rc = iops->load(env, it, rdpg->rp_hash);
812 * Iterator didn't find record with exactly the key requested.
814 * It is currently either
816 * - positioned above record with key less than
817 * requested---skip it.
818 * - or not positioned at all (is in IAM_IT_SKEWED
819 * state)---position it on the next item.
821 rc = iops->next(env, it);
830 /* Fill containers one after the other. There might be multiple
831 * containers per physical page.
833 * At this point and across for-loop:
834 * rc == 0 -> ok, proceed.
835 * rc > 0 -> end of index.
836 * rc < 0 -> error. */
837 for (pageidx = 0; rc == 0 && nob > 0; pageidx++) {
841 LASSERT(pageidx < rdpg->rp_npages);
842 lp = kmap(rdpg->rp_pages[pageidx]);
845 for (i = 0; i < LU_PAGE_COUNT; i++, lp++, nob -= LU_PAGE_SIZE) {
846 rc = filler(env, lp, min_t(int, nob, LU_PAGE_SIZE),
847 iops, it, rdpg->rp_attrs, arg);
850 /* one more lu_page */
856 kunmap(rdpg->rp_pages[i]);
864 rc = min_t(unsigned int, nlupgs * LU_PAGE_SIZE, rdpg->rp_count);
868 EXPORT_SYMBOL(dt_index_walk);
871 * Walk key/record pairs of an index and copy them into 4KB containers to be
872 * transferred over the network. This is the common handler for OBD_IDX_READ
875 * \param env - is the environment passed by the caller
876 * \param dev - is the dt_device storing the index
877 * \param ii - is the idx_info structure packed by the client in the
878 * OBD_IDX_READ request
879 * \param rdpg - is the lu_rdpg descriptor
881 * \retval on success, return sum (in bytes) of all filled containers
882 * \retval appropriate error otherwise.
884 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
885 struct idx_info *ii, const struct lu_rdpg *rdpg)
887 const struct dt_index_features *feat;
888 struct dt_object *obj;
892 /* rp_count shouldn't be null and should be a multiple of the container
894 if (rdpg->rp_count <= 0 && (rdpg->rp_count & (LU_PAGE_SIZE - 1)) != 0)
897 if (!fid_is_quota(&ii->ii_fid) && !fid_is_layout_rbtree(&ii->ii_fid) &&
898 !fid_is_norm(&ii->ii_fid))
901 /* lookup index object subject to the transfer */
902 obj = dt_locate(env, dev, &ii->ii_fid);
904 RETURN(PTR_ERR(obj));
905 if (dt_object_exists(obj) == 0)
906 GOTO(out, rc = -ENOENT);
908 /* fetch index features associated with index object */
909 feat = dt_index_feat_select(fid_seq(&ii->ii_fid),
910 lu_object_attr(&obj->do_lu));
912 GOTO(out, rc = PTR_ERR(feat));
914 /* load index feature if not done already */
915 if (obj->do_index_ops == NULL) {
916 rc = obj->do_ops->do_index_try(env, obj, feat);
921 /* fill ii_flags with supported index features */
922 ii->ii_flags &= (II_FL_NOHASH | II_FL_NOKEY | II_FL_VARKEY |
925 if (!(feat->dif_flags & DT_IND_VARKEY))
926 ii->ii_keysize = feat->dif_keysize_max;
928 if (!(feat->dif_flags & DT_IND_VARREC))
929 ii->ii_recsize = feat->dif_recsize_max;
931 if (!(feat->dif_flags & DT_IND_NONUNQ))
932 /* key isn't necessarily unique */
933 ii->ii_flags |= II_FL_NONUNQ;
935 if (!fid_is_layout_rbtree(&ii->ii_fid)) {
936 dt_read_lock(env, obj, 0);
937 /* fetch object version before walking the index */
938 ii->ii_version = dt_version_get(env, obj);
941 /* walk the index and fill lu_idxpages with key/record pairs */
942 rc = dt_index_walk(env, obj, rdpg, dt_index_page_build, ii);
943 if (!fid_is_layout_rbtree(&ii->ii_fid))
944 dt_read_unlock(env, obj);
948 LASSERT(ii->ii_count == 0);
949 ii->ii_hash_end = II_END_OFF;
954 lu_object_put(env, &obj->do_lu);
957 EXPORT_SYMBOL(dt_index_read);
960 #ifndef HAVE_ONLY_PROCFS_SEQ
961 int lprocfs_dt_rd_blksize(char *page, char **start, off_t off,
962 int count, int *eof, void *data)
964 struct dt_device *dt = data;
965 struct obd_statfs osfs;
967 int rc = dt_statfs(NULL, dt, &osfs);
970 rc = snprintf(page, count, "%u\n",
971 (unsigned) osfs.os_bsize);
976 EXPORT_SYMBOL(lprocfs_dt_rd_blksize);
978 int lprocfs_dt_rd_kbytestotal(char *page, char **start, off_t off,
979 int count, int *eof, void *data)
981 struct dt_device *dt = data;
982 struct obd_statfs osfs;
984 int rc = dt_statfs(NULL, dt, &osfs);
986 __u32 blk_size = osfs.os_bsize >> 10;
987 __u64 result = osfs.os_blocks;
989 while (blk_size >>= 1)
993 rc = snprintf(page, count, LPU64"\n", result);
998 EXPORT_SYMBOL(lprocfs_dt_rd_kbytestotal);
1000 int lprocfs_dt_rd_kbytesfree(char *page, char **start, off_t off,
1001 int count, int *eof, void *data)
1003 struct dt_device *dt = data;
1004 struct obd_statfs osfs;
1006 int rc = dt_statfs(NULL, dt, &osfs);
1008 __u32 blk_size = osfs.os_bsize >> 10;
1009 __u64 result = osfs.os_bfree;
1011 while (blk_size >>= 1)
1015 rc = snprintf(page, count, LPU64"\n", result);
1020 EXPORT_SYMBOL(lprocfs_dt_rd_kbytesfree);
1022 int lprocfs_dt_rd_kbytesavail(char *page, char **start, off_t off,
1023 int count, int *eof, void *data)
1025 struct dt_device *dt = data;
1026 struct obd_statfs osfs;
1028 int rc = dt_statfs(NULL, dt, &osfs);
1030 __u32 blk_size = osfs.os_bsize >> 10;
1031 __u64 result = osfs.os_bavail;
1033 while (blk_size >>= 1)
1037 rc = snprintf(page, count, LPU64"\n", result);
1042 EXPORT_SYMBOL(lprocfs_dt_rd_kbytesavail);
1044 int lprocfs_dt_rd_filestotal(char *page, char **start, off_t off,
1045 int count, int *eof, void *data)
1047 struct dt_device *dt = data;
1048 struct obd_statfs osfs;
1050 int rc = dt_statfs(NULL, dt, &osfs);
1053 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
1058 EXPORT_SYMBOL(lprocfs_dt_rd_filestotal);
1060 int lprocfs_dt_rd_filesfree(char *page, char **start, off_t off,
1061 int count, int *eof, void *data)
1063 struct dt_device *dt = data;
1064 struct obd_statfs osfs;
1066 int rc = dt_statfs(NULL, dt, &osfs);
1069 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
1074 EXPORT_SYMBOL(lprocfs_dt_rd_filesfree);
1077 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v)
1079 struct dt_device *dt = m->private;
1080 struct obd_statfs osfs;
1082 int rc = dt_statfs(NULL, dt, &osfs);
1084 seq_printf(m, "%u\n", (unsigned) osfs.os_bsize);
1087 EXPORT_SYMBOL(lprocfs_dt_blksize_seq_show);
1089 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v)
1091 struct dt_device *dt = m->private;
1092 struct obd_statfs osfs;
1094 int rc = dt_statfs(NULL, dt, &osfs);
1096 __u32 blk_size = osfs.os_bsize >> 10;
1097 __u64 result = osfs.os_blocks;
1099 while (blk_size >>= 1)
1102 seq_printf(m, LPU64"\n", result);
1106 EXPORT_SYMBOL(lprocfs_dt_kbytestotal_seq_show);
1108 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v)
1110 struct dt_device *dt = m->private;
1111 struct obd_statfs osfs;
1113 int rc = dt_statfs(NULL, dt, &osfs);
1115 __u32 blk_size = osfs.os_bsize >> 10;
1116 __u64 result = osfs.os_bfree;
1118 while (blk_size >>= 1)
1121 seq_printf(m, LPU64"\n", result);
1125 EXPORT_SYMBOL(lprocfs_dt_kbytesfree_seq_show);
1127 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v)
1129 struct dt_device *dt = m->private;
1130 struct obd_statfs osfs;
1132 int rc = dt_statfs(NULL, dt, &osfs);
1134 __u32 blk_size = osfs.os_bsize >> 10;
1135 __u64 result = osfs.os_bavail;
1137 while (blk_size >>= 1)
1140 seq_printf(m, LPU64"\n", result);
1144 EXPORT_SYMBOL(lprocfs_dt_kbytesavail_seq_show);
1146 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v)
1148 struct dt_device *dt = m->private;
1149 struct obd_statfs osfs;
1151 int rc = dt_statfs(NULL, dt, &osfs);
1153 seq_printf(m, LPU64"\n", osfs.os_files);
1156 EXPORT_SYMBOL(lprocfs_dt_filestotal_seq_show);
1158 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v)
1160 struct dt_device *dt = m->private;
1161 struct obd_statfs osfs;
1163 int rc = dt_statfs(NULL, dt, &osfs);
1165 seq_printf(m, LPU64"\n", osfs.os_ffree);
1168 EXPORT_SYMBOL(lprocfs_dt_filesfree_seq_show);
1170 #endif /* LPROCFS */