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 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 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 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 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 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)
139 INIT_LIST_HEAD(&dev->dd_txn_callbacks);
140 return lu_device_init(&dev->dd_lu_dev, t);
142 EXPORT_SYMBOL(dt_device_init);
144 void dt_device_fini(struct dt_device *dev)
146 lu_device_fini(&dev->dd_lu_dev);
148 EXPORT_SYMBOL(dt_device_fini);
150 int dt_object_init(struct dt_object *obj,
151 struct lu_object_header *h, struct lu_device *d)
154 return lu_object_init(&obj->do_lu, h, d);
156 EXPORT_SYMBOL(dt_object_init);
158 void dt_object_fini(struct dt_object *obj)
160 lu_object_fini(&obj->do_lu);
162 EXPORT_SYMBOL(dt_object_fini);
164 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj)
166 if (obj->do_index_ops == NULL)
167 obj->do_ops->do_index_try(env, obj, &dt_directory_features);
168 return obj->do_index_ops != NULL;
170 EXPORT_SYMBOL(dt_try_as_dir);
172 enum dt_format_type dt_mode_to_dft(__u32 mode)
174 enum dt_format_type result;
176 switch (mode & S_IFMT) {
181 result = DFT_REGULAR;
198 EXPORT_SYMBOL(dt_mode_to_dft);
201 * lookup fid for object named \a name in directory \a dir.
204 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
205 const char *name, struct lu_fid *fid)
207 if (dt_try_as_dir(env, dir))
208 return dt_lookup(env, dir, (struct dt_rec *)fid,
209 (const struct dt_key *)name, BYPASS_CAPA);
212 EXPORT_SYMBOL(dt_lookup_dir);
214 /* this differs from dt_locate by top_dev as parameter
215 * but not one from lu_site */
216 struct dt_object *dt_locate_at(const struct lu_env *env,
217 struct dt_device *dev,
218 const struct lu_fid *fid,
219 struct lu_device *top_dev,
220 const struct lu_object_conf *conf)
222 struct lu_object *lo;
225 lo = lu_object_find_at(env, top_dev, fid, conf);
227 return ERR_PTR(PTR_ERR(lo));
231 list_for_each_entry(n, &lo->lo_header->loh_layers, lo_linkage) {
232 if (n->lo_dev == &dev->dd_lu_dev)
233 return container_of0(n, struct dt_object, do_lu);
236 return ERR_PTR(-ENOENT);
238 EXPORT_SYMBOL(dt_locate_at);
241 * find a object named \a entry in given \a dfh->dfh_o directory.
243 static int dt_find_entry(const struct lu_env *env, const char *entry, void *data)
245 struct dt_find_hint *dfh = data;
246 struct dt_device *dt = dfh->dfh_dt;
247 struct lu_fid *fid = dfh->dfh_fid;
248 struct dt_object *obj = dfh->dfh_o;
251 result = dt_lookup_dir(env, obj, entry, fid);
252 lu_object_put(env, &obj->do_lu);
254 obj = dt_locate(env, dt, fid);
256 result = PTR_ERR(obj);
263 * Abstract function which parses path name. This function feeds
264 * path component to \a entry_func.
266 int dt_path_parser(const struct lu_env *env,
267 char *path, dt_entry_func_t entry_func,
274 e = strsep(&path, "/");
279 if (!path || path[0] == '\0')
283 rc = entry_func(env, e, data);
292 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
293 const char *path, struct lu_fid *fid)
295 struct dt_thread_info *info = dt_info(env);
296 struct dt_find_hint *dfh = &info->dti_dfh;
297 struct dt_object *obj;
304 strlcpy(info->dti_buf, path, sizeof(info->dti_buf));
306 result = dt->dd_ops->dt_root_get(env, dt, fid);
308 obj = dt_locate(env, dt, fid);
311 result = dt_path_parser(env, info->dti_buf,
314 obj = ERR_PTR(result);
319 obj = ERR_PTR(result);
323 EXPORT_SYMBOL(dt_store_resolve);
325 static struct dt_object *dt_reg_open(const struct lu_env *env,
326 struct dt_device *dt,
334 result = dt_lookup_dir(env, p, name, fid);
336 o = dt_locate(env, dt, fid);
345 * Open dt object named \a filename from \a dirname directory.
346 * \param dt dt device
347 * \param fid on success, object fid is stored in *fid
349 struct dt_object *dt_store_open(const struct lu_env *env,
350 struct dt_device *dt,
352 const char *filename,
355 struct dt_object *file;
356 struct dt_object *dir;
358 dir = dt_store_resolve(env, dt, dirname, fid);
360 file = dt_reg_open(env, dt, dir,
362 lu_object_put(env, &dir->do_lu);
368 EXPORT_SYMBOL(dt_store_open);
370 struct dt_object *dt_find_or_create(const struct lu_env *env,
371 struct dt_device *dt,
372 const struct lu_fid *fid,
373 struct dt_object_format *dof,
376 struct dt_object *dto;
382 dto = dt_locate(env, dt, fid);
386 LASSERT(dto != NULL);
387 if (dt_object_exists(dto))
390 th = dt_trans_create(env, dt);
392 GOTO(out, rc = PTR_ERR(th));
394 rc = dt_declare_create(env, dto, at, NULL, dof, th);
396 GOTO(trans_stop, rc);
398 rc = dt_trans_start_local(env, dt, th);
400 GOTO(trans_stop, rc);
402 dt_write_lock(env, dto, 0);
403 if (dt_object_exists(dto))
404 GOTO(unlock, rc = 0);
406 CDEBUG(D_OTHER, "create new object "DFID"\n", PFID(fid));
408 rc = dt_create(env, dto, at, NULL, dof, th);
411 LASSERT(dt_object_exists(dto));
413 dt_write_unlock(env, dto);
415 dt_trans_stop(env, dt, th);
418 lu_object_put(env, &dto->do_lu);
423 EXPORT_SYMBOL(dt_find_or_create);
425 /* dt class init function. */
426 int dt_global_init(void)
430 LU_CONTEXT_KEY_INIT(&dt_key);
431 result = lu_context_key_register(&dt_key);
435 void dt_global_fini(void)
437 lu_context_key_degister(&dt_key);
441 * Generic read helper. May return an error for partial reads.
443 * \param env lustre environment
444 * \param dt object to be read
445 * \param buf lu_buf to be filled, with buffer pointer and length
446 * \param pos position to start reading, updated as data is read
448 * \retval real size of data read
449 * \retval -ve errno on failure
451 int dt_read(const struct lu_env *env, struct dt_object *dt,
452 struct lu_buf *buf, loff_t *pos)
454 LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
455 return dt->do_body_ops->dbo_read(env, dt, buf, pos, BYPASS_CAPA);
457 EXPORT_SYMBOL(dt_read);
460 * Read structures of fixed size from storage. Unlike dt_read(), using
461 * dt_record_read() will return an error for partial reads.
463 * \param env lustre environment
464 * \param dt object to be read
465 * \param buf lu_buf to be filled, with buffer pointer and length
466 * \param pos position to start reading, updated as data is read
468 * \retval 0 on successfully reading full buffer
469 * \retval -EFAULT on short read
470 * \retval -ve errno on failure
472 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
473 struct lu_buf *buf, loff_t *pos)
477 LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
479 rc = dt->do_body_ops->dbo_read(env, dt, buf, pos, BYPASS_CAPA);
481 if (rc == buf->lb_len)
487 EXPORT_SYMBOL(dt_record_read);
489 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
490 const struct lu_buf *buf, loff_t *pos, struct thandle *th)
494 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
496 LASSERT(dt->do_body_ops);
497 LASSERT(dt->do_body_ops->dbo_write);
498 rc = dt->do_body_ops->dbo_write(env, dt, buf, pos, th, BYPASS_CAPA, 1);
499 if (rc == buf->lb_len)
505 EXPORT_SYMBOL(dt_record_write);
507 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
511 char *xname = XATTR_NAME_VERSION;
515 vbuf.lb_len = sizeof(dt_obj_version_t);
516 return dt_declare_xattr_set(env, o, &vbuf, xname, 0, th);
519 EXPORT_SYMBOL(dt_declare_version_set);
521 void dt_version_set(const struct lu_env *env, struct dt_object *o,
522 dt_obj_version_t version, struct thandle *th)
525 char *xname = XATTR_NAME_VERSION;
529 vbuf.lb_buf = &version;
530 vbuf.lb_len = sizeof(version);
532 rc = dt_xattr_set(env, o, &vbuf, xname, 0, th, BYPASS_CAPA);
534 CDEBUG(D_INODE, "Can't set version, rc %d\n", rc);
537 EXPORT_SYMBOL(dt_version_set);
539 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o)
542 char *xname = XATTR_NAME_VERSION;
543 dt_obj_version_t version;
547 vbuf.lb_buf = &version;
548 vbuf.lb_len = sizeof(version);
549 rc = dt_xattr_get(env, o, &vbuf, xname, BYPASS_CAPA);
550 if (rc != sizeof(version)) {
551 CDEBUG(D_INODE, "Can't get version, rc %d\n", rc);
556 EXPORT_SYMBOL(dt_version_get);
558 /* list of all supported index types */
561 const struct dt_index_features dt_directory_features;
562 EXPORT_SYMBOL(dt_directory_features);
565 const struct dt_index_features dt_otable_features;
566 EXPORT_SYMBOL(dt_otable_features);
569 const struct dt_index_features dt_lfsck_orphan_features = {
571 .dif_keysize_min = sizeof(struct lu_fid),
572 .dif_keysize_max = sizeof(struct lu_fid),
573 .dif_recsize_min = sizeof(struct lu_orphan_rec),
574 .dif_recsize_max = sizeof(struct lu_orphan_rec),
577 EXPORT_SYMBOL(dt_lfsck_orphan_features);
580 const struct dt_index_features dt_lfsck_features = {
581 .dif_flags = DT_IND_UPDATE,
582 .dif_keysize_min = sizeof(struct lu_fid),
583 .dif_keysize_max = sizeof(struct lu_fid),
584 .dif_recsize_min = sizeof(__u8),
585 .dif_recsize_max = sizeof(__u8),
588 EXPORT_SYMBOL(dt_lfsck_features);
590 /* accounting indexes */
591 const struct dt_index_features dt_acct_features = {
592 .dif_flags = DT_IND_UPDATE,
593 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
594 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
595 .dif_recsize_min = sizeof(struct lquota_acct_rec), /* 16 bytes */
596 .dif_recsize_max = sizeof(struct lquota_acct_rec), /* 16 bytes */
599 EXPORT_SYMBOL(dt_acct_features);
601 /* global quota files */
602 const struct dt_index_features dt_quota_glb_features = {
603 .dif_flags = DT_IND_UPDATE,
604 /* a different key would have to be used for per-directory quota */
605 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
606 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
607 .dif_recsize_min = sizeof(struct lquota_glb_rec), /* 32 bytes */
608 .dif_recsize_max = sizeof(struct lquota_glb_rec), /* 32 bytes */
611 EXPORT_SYMBOL(dt_quota_glb_features);
613 /* slave quota files */
614 const struct dt_index_features dt_quota_slv_features = {
615 .dif_flags = DT_IND_UPDATE,
616 /* a different key would have to be used for per-directory quota */
617 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
618 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
619 .dif_recsize_min = sizeof(struct lquota_slv_rec), /* 8 bytes */
620 .dif_recsize_max = sizeof(struct lquota_slv_rec), /* 8 bytes */
623 EXPORT_SYMBOL(dt_quota_slv_features);
625 /* helper function returning what dt_index_features structure should be used
626 * based on the FID sequence. This is used by OBD_IDX_READ RPC */
627 static inline const struct dt_index_features *dt_index_feat_select(__u64 seq,
630 if (seq == FID_SEQ_QUOTA_GLB) {
631 /* global quota index */
633 /* global quota index should be a regular file */
634 return ERR_PTR(-ENOENT);
635 return &dt_quota_glb_features;
636 } else if (seq == FID_SEQ_QUOTA) {
637 /* quota slave index */
639 /* slave index should be a regular file */
640 return ERR_PTR(-ENOENT);
641 return &dt_quota_slv_features;
642 } else if (seq == FID_SEQ_LAYOUT_RBTREE){
643 return &dt_lfsck_orphan_features;
644 } else if (seq >= FID_SEQ_NORMAL) {
645 /* object is part of the namespace, verify that it is a
648 /* sorry, we can only deal with directory */
649 return ERR_PTR(-ENOTDIR);
650 return &dt_directory_features;
653 return ERR_PTR(-EOPNOTSUPP);
657 * Fill a lu_idxpage with key/record pairs read for transfer via OBD_IDX_READ
660 * \param env - is the environment passed by the caller
661 * \param lp - is a pointer to the lu_page to fill
662 * \param nob - is the maximum number of bytes that should be copied
663 * \param iops - is the index operation vector associated with the index object
664 * \param it - is a pointer to the current iterator
665 * \param attr - is the index attribute to pass to iops->rec()
666 * \param arg - is a pointer to the idx_info structure
668 static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
669 int nob, const struct dt_it_ops *iops,
670 struct dt_it *it, __u32 attr, void *arg)
672 struct idx_info *ii = (struct idx_info *)arg;
673 struct lu_idxpage *lip = &lp->lp_idx;
678 /* initialize the header of the new container */
679 memset(lip, 0, LIP_HDR_SIZE);
680 lip->lip_magic = LIP_MAGIC;
683 /* compute size needed to store a key/record pair */
684 size = ii->ii_recsize + ii->ii_keysize;
685 if ((ii->ii_flags & II_FL_NOHASH) == 0)
686 /* add hash if the client wants it */
687 size += sizeof(__u64);
689 entry = lip->lip_entries;
691 char *tmp_entry = entry;
697 /* fetch 64-bit hash value */
698 hash = iops->store(env, it);
699 ii->ii_hash_end = hash;
701 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_IDX_READ_BREAK)) {
702 if (lip->lip_nr != 0)
707 if (lip->lip_nr == 0)
708 GOTO(out, rc = -EINVAL);
712 if (!(ii->ii_flags & II_FL_NOHASH)) {
713 /* client wants to the 64-bit hash value associated with
715 memcpy(tmp_entry, &hash, sizeof(hash));
716 tmp_entry += sizeof(hash);
719 if (ii->ii_flags & II_FL_VARKEY)
720 keysize = iops->key_size(env, it);
722 keysize = ii->ii_keysize;
724 if (!(ii->ii_flags & II_FL_NOKEY)) {
725 /* then the key value */
726 key = iops->key(env, it);
727 memcpy(tmp_entry, key, keysize);
728 tmp_entry += keysize;
731 /* and finally the record */
732 rc = iops->rec(env, it, (struct dt_rec *)tmp_entry, attr);
737 /* hash/key/record successfully copied! */
739 if (unlikely(lip->lip_nr == 1 && ii->ii_count == 0))
740 ii->ii_hash_start = hash;
742 if (ii->ii_flags & II_FL_VARREC)
743 recsize = iops->rec_size(env, it, attr);
745 recsize = ii->ii_recsize;
747 entry = tmp_entry + recsize;
751 /* move on to the next record */
753 rc = iops->next(env, it);
754 } while (rc == -ESTALE);
760 if (rc >= 0 && lip->lip_nr > 0)
761 /* one more container */
764 /* no more entries */
765 ii->ii_hash_end = II_END_OFF;
771 * Walk index and fill lu_page containers with key/record pairs
773 * \param env - is the environment passed by the caller
774 * \param obj - is the index object to parse
775 * \param rdpg - is the lu_rdpg descriptor associated with the transfer
776 * \param filler - is the callback function responsible for filling a lu_page
777 * with key/record pairs in the format wanted by the caller
778 * \param arg - is an opaq argument passed to the filler function
780 * \retval sum (in bytes) of all filled lu_pages
781 * \retval -ve errno on failure
783 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
784 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
788 const struct dt_it_ops *iops;
789 unsigned int pageidx, nob, nlupgs = 0;
793 LASSERT(rdpg->rp_pages != NULL);
794 LASSERT(obj->do_index_ops != NULL);
796 nob = rdpg->rp_count;
800 /* Iterate through index and fill containers from @rdpg */
801 iops = &obj->do_index_ops->dio_it;
802 LASSERT(iops != NULL);
803 it = iops->init(env, obj, rdpg->rp_attrs, BYPASS_CAPA);
807 rc = iops->load(env, it, rdpg->rp_hash);
810 * Iterator didn't find record with exactly the key requested.
812 * It is currently either
814 * - positioned above record with key less than
815 * requested---skip it.
816 * - or not positioned at all (is in IAM_IT_SKEWED
817 * state)---position it on the next item.
819 rc = iops->next(env, it);
828 /* Fill containers one after the other. There might be multiple
829 * containers per physical page.
831 * At this point and across for-loop:
832 * rc == 0 -> ok, proceed.
833 * rc > 0 -> end of index.
834 * rc < 0 -> error. */
835 for (pageidx = 0; rc == 0 && nob > 0; pageidx++) {
839 LASSERT(pageidx < rdpg->rp_npages);
840 lp = kmap(rdpg->rp_pages[pageidx]);
843 for (i = 0; i < LU_PAGE_COUNT; i++, lp++, nob -= LU_PAGE_SIZE) {
844 rc = filler(env, lp, min_t(int, nob, LU_PAGE_SIZE),
845 iops, it, rdpg->rp_attrs, arg);
848 /* one more lu_page */
854 kunmap(rdpg->rp_pages[i]);
862 rc = min_t(unsigned int, nlupgs * LU_PAGE_SIZE, rdpg->rp_count);
866 EXPORT_SYMBOL(dt_index_walk);
869 * Walk key/record pairs of an index and copy them into 4KB containers to be
870 * transferred over the network. This is the common handler for OBD_IDX_READ
873 * \param env - is the environment passed by the caller
874 * \param dev - is the dt_device storing the index
875 * \param ii - is the idx_info structure packed by the client in the
876 * OBD_IDX_READ request
877 * \param rdpg - is the lu_rdpg descriptor
879 * \retval on success, return sum (in bytes) of all filled containers
880 * \retval appropriate error otherwise.
882 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
883 struct idx_info *ii, const struct lu_rdpg *rdpg)
885 const struct dt_index_features *feat;
886 struct dt_object *obj;
890 /* rp_count shouldn't be null and should be a multiple of the container
892 if (rdpg->rp_count <= 0 && (rdpg->rp_count & (LU_PAGE_SIZE - 1)) != 0)
895 if (!fid_is_quota(&ii->ii_fid) && !fid_is_layout_rbtree(&ii->ii_fid) &&
896 !fid_is_norm(&ii->ii_fid))
899 /* lookup index object subject to the transfer */
900 obj = dt_locate(env, dev, &ii->ii_fid);
902 RETURN(PTR_ERR(obj));
903 if (dt_object_exists(obj) == 0)
904 GOTO(out, rc = -ENOENT);
906 /* fetch index features associated with index object */
907 feat = dt_index_feat_select(fid_seq(&ii->ii_fid),
908 lu_object_attr(&obj->do_lu));
910 GOTO(out, rc = PTR_ERR(feat));
912 /* load index feature if not done already */
913 if (obj->do_index_ops == NULL) {
914 rc = obj->do_ops->do_index_try(env, obj, feat);
919 /* fill ii_flags with supported index features */
920 ii->ii_flags &= (II_FL_NOHASH | II_FL_NOKEY | II_FL_VARKEY |
923 if (!(feat->dif_flags & DT_IND_VARKEY))
924 ii->ii_keysize = feat->dif_keysize_max;
926 if (!(feat->dif_flags & DT_IND_VARREC))
927 ii->ii_recsize = feat->dif_recsize_max;
929 if (!(feat->dif_flags & DT_IND_NONUNQ))
930 /* key isn't necessarily unique */
931 ii->ii_flags |= II_FL_NONUNQ;
933 if (!fid_is_layout_rbtree(&ii->ii_fid)) {
934 dt_read_lock(env, obj, 0);
935 /* fetch object version before walking the index */
936 ii->ii_version = dt_version_get(env, obj);
939 /* walk the index and fill lu_idxpages with key/record pairs */
940 rc = dt_index_walk(env, obj, rdpg, dt_index_page_build, ii);
941 if (!fid_is_layout_rbtree(&ii->ii_fid))
942 dt_read_unlock(env, obj);
946 LASSERT(ii->ii_count == 0);
947 ii->ii_hash_end = II_END_OFF;
952 lu_object_put(env, &obj->do_lu);
955 EXPORT_SYMBOL(dt_index_read);
958 #ifndef HAVE_ONLY_PROCFS_SEQ
959 int lprocfs_dt_rd_blksize(char *page, char **start, off_t off,
960 int count, int *eof, void *data)
962 struct dt_device *dt = data;
963 struct obd_statfs osfs;
965 int rc = dt_statfs(NULL, dt, &osfs);
968 rc = snprintf(page, count, "%u\n",
969 (unsigned) osfs.os_bsize);
974 EXPORT_SYMBOL(lprocfs_dt_rd_blksize);
976 int lprocfs_dt_rd_kbytestotal(char *page, char **start, off_t off,
977 int count, int *eof, void *data)
979 struct dt_device *dt = data;
980 struct obd_statfs osfs;
982 int rc = dt_statfs(NULL, dt, &osfs);
984 __u32 blk_size = osfs.os_bsize >> 10;
985 __u64 result = osfs.os_blocks;
987 while (blk_size >>= 1)
991 rc = snprintf(page, count, LPU64"\n", result);
996 EXPORT_SYMBOL(lprocfs_dt_rd_kbytestotal);
998 int lprocfs_dt_rd_kbytesfree(char *page, char **start, off_t off,
999 int count, int *eof, void *data)
1001 struct dt_device *dt = data;
1002 struct obd_statfs osfs;
1004 int rc = dt_statfs(NULL, dt, &osfs);
1006 __u32 blk_size = osfs.os_bsize >> 10;
1007 __u64 result = osfs.os_bfree;
1009 while (blk_size >>= 1)
1013 rc = snprintf(page, count, LPU64"\n", result);
1018 EXPORT_SYMBOL(lprocfs_dt_rd_kbytesfree);
1020 int lprocfs_dt_rd_kbytesavail(char *page, char **start, off_t off,
1021 int count, int *eof, void *data)
1023 struct dt_device *dt = data;
1024 struct obd_statfs osfs;
1026 int rc = dt_statfs(NULL, dt, &osfs);
1028 __u32 blk_size = osfs.os_bsize >> 10;
1029 __u64 result = osfs.os_bavail;
1031 while (blk_size >>= 1)
1035 rc = snprintf(page, count, LPU64"\n", result);
1040 EXPORT_SYMBOL(lprocfs_dt_rd_kbytesavail);
1042 int lprocfs_dt_rd_filestotal(char *page, char **start, off_t off,
1043 int count, int *eof, void *data)
1045 struct dt_device *dt = data;
1046 struct obd_statfs osfs;
1048 int rc = dt_statfs(NULL, dt, &osfs);
1051 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
1056 EXPORT_SYMBOL(lprocfs_dt_rd_filestotal);
1058 int lprocfs_dt_rd_filesfree(char *page, char **start, off_t off,
1059 int count, int *eof, void *data)
1061 struct dt_device *dt = data;
1062 struct obd_statfs osfs;
1064 int rc = dt_statfs(NULL, dt, &osfs);
1067 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
1072 EXPORT_SYMBOL(lprocfs_dt_rd_filesfree);
1075 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v)
1077 struct dt_device *dt = m->private;
1078 struct obd_statfs osfs;
1080 int rc = dt_statfs(NULL, dt, &osfs);
1082 seq_printf(m, "%u\n", (unsigned) osfs.os_bsize);
1085 EXPORT_SYMBOL(lprocfs_dt_blksize_seq_show);
1087 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v)
1089 struct dt_device *dt = m->private;
1090 struct obd_statfs osfs;
1092 int rc = dt_statfs(NULL, dt, &osfs);
1094 __u32 blk_size = osfs.os_bsize >> 10;
1095 __u64 result = osfs.os_blocks;
1097 while (blk_size >>= 1)
1100 seq_printf(m, LPU64"\n", result);
1104 EXPORT_SYMBOL(lprocfs_dt_kbytestotal_seq_show);
1106 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v)
1108 struct dt_device *dt = m->private;
1109 struct obd_statfs osfs;
1111 int rc = dt_statfs(NULL, dt, &osfs);
1113 __u32 blk_size = osfs.os_bsize >> 10;
1114 __u64 result = osfs.os_bfree;
1116 while (blk_size >>= 1)
1119 seq_printf(m, LPU64"\n", result);
1123 EXPORT_SYMBOL(lprocfs_dt_kbytesfree_seq_show);
1125 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v)
1127 struct dt_device *dt = m->private;
1128 struct obd_statfs osfs;
1130 int rc = dt_statfs(NULL, dt, &osfs);
1132 __u32 blk_size = osfs.os_bsize >> 10;
1133 __u64 result = osfs.os_bavail;
1135 while (blk_size >>= 1)
1138 seq_printf(m, LPU64"\n", result);
1142 EXPORT_SYMBOL(lprocfs_dt_kbytesavail_seq_show);
1144 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v)
1146 struct dt_device *dt = m->private;
1147 struct obd_statfs osfs;
1149 int rc = dt_statfs(NULL, dt, &osfs);
1151 seq_printf(m, LPU64"\n", osfs.os_files);
1154 EXPORT_SYMBOL(lprocfs_dt_filestotal_seq_show);
1156 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v)
1158 struct dt_device *dt = m->private;
1159 struct obd_statfs osfs;
1161 int rc = dt_statfs(NULL, dt, &osfs);
1163 seq_printf(m, LPU64"\n", osfs.os_ffree);
1166 EXPORT_SYMBOL(lprocfs_dt_filesfree_seq_show);
1168 #endif /* LPROCFS */