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, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/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
64 /* no lock is necessary to protect the list, because call-backs
65 * are added during system startup. Please refer to "struct dt_device".
67 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb)
69 list_add(&cb->dtc_linkage, &dev->dd_txn_callbacks);
71 EXPORT_SYMBOL(dt_txn_callback_add);
73 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb)
75 list_del_init(&cb->dtc_linkage);
77 EXPORT_SYMBOL(dt_txn_callback_del);
79 int dt_txn_hook_start(const struct lu_env *env,
80 struct dt_device *dev, struct thandle *th)
83 struct dt_txn_callback *cb;
88 list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
89 if (cb->dtc_txn_start == NULL ||
90 !(cb->dtc_tag & env->le_ctx.lc_tags))
92 rc = cb->dtc_txn_start(env, th, cb->dtc_cookie);
98 EXPORT_SYMBOL(dt_txn_hook_start);
100 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn)
102 struct dt_device *dev = txn->th_dev;
103 struct dt_txn_callback *cb;
109 list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
110 if (cb->dtc_txn_stop == NULL ||
111 !(cb->dtc_tag & env->le_ctx.lc_tags))
113 rc = cb->dtc_txn_stop(env, txn, cb->dtc_cookie);
119 EXPORT_SYMBOL(dt_txn_hook_stop);
121 void dt_txn_hook_commit(struct thandle *txn)
123 struct dt_txn_callback *cb;
128 list_for_each_entry(cb, &txn->th_dev->dd_txn_callbacks,
130 if (cb->dtc_txn_commit)
131 cb->dtc_txn_commit(txn, cb->dtc_cookie);
134 EXPORT_SYMBOL(dt_txn_hook_commit);
136 int dt_device_init(struct dt_device *dev, struct lu_device_type *t)
138 INIT_LIST_HEAD(&dev->dd_txn_callbacks);
139 return lu_device_init(&dev->dd_lu_dev, t);
141 EXPORT_SYMBOL(dt_device_init);
143 void dt_device_fini(struct dt_device *dev)
145 lu_device_fini(&dev->dd_lu_dev);
147 EXPORT_SYMBOL(dt_device_fini);
149 int dt_object_init(struct dt_object *obj,
150 struct lu_object_header *h, struct lu_device *d)
153 return lu_object_init(&obj->do_lu, h, d);
155 EXPORT_SYMBOL(dt_object_init);
157 void dt_object_fini(struct dt_object *obj)
159 lu_object_fini(&obj->do_lu);
161 EXPORT_SYMBOL(dt_object_fini);
163 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj)
165 if (obj->do_index_ops == NULL)
166 obj->do_ops->do_index_try(env, obj, &dt_directory_features);
167 return obj->do_index_ops != NULL;
169 EXPORT_SYMBOL(dt_try_as_dir);
171 enum dt_format_type dt_mode_to_dft(__u32 mode)
173 enum dt_format_type result;
175 switch (mode & S_IFMT) {
180 result = DFT_REGULAR;
197 EXPORT_SYMBOL(dt_mode_to_dft);
200 * lookup fid for object named \a name in directory \a dir.
203 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
204 const char *name, struct lu_fid *fid)
206 if (dt_try_as_dir(env, dir))
207 return dt_lookup(env, dir, (struct dt_rec *)fid,
208 (const struct dt_key *)name, BYPASS_CAPA);
211 EXPORT_SYMBOL(dt_lookup_dir);
213 /* this differs from dt_locate by top_dev as parameter
214 * but not one from lu_site */
215 struct dt_object *dt_locate_at(const struct lu_env *env,
216 struct dt_device *dev,
217 const struct lu_fid *fid,
218 struct lu_device *top_dev,
219 const struct lu_object_conf *conf)
221 struct lu_object *lo;
224 lo = lu_object_find_at(env, top_dev, fid, conf);
226 return ERR_PTR(PTR_ERR(lo));
230 list_for_each_entry(n, &lo->lo_header->loh_layers, lo_linkage) {
231 if (n->lo_dev == &dev->dd_lu_dev)
232 return container_of0(n, struct dt_object, do_lu);
235 return ERR_PTR(-ENOENT);
237 EXPORT_SYMBOL(dt_locate_at);
240 * find a object named \a entry in given \a dfh->dfh_o directory.
242 static int dt_find_entry(const struct lu_env *env, const char *entry, void *data)
244 struct dt_find_hint *dfh = data;
245 struct dt_device *dt = dfh->dfh_dt;
246 struct lu_fid *fid = dfh->dfh_fid;
247 struct dt_object *obj = dfh->dfh_o;
250 result = dt_lookup_dir(env, obj, entry, fid);
251 lu_object_put(env, &obj->do_lu);
253 obj = dt_locate(env, dt, fid);
255 result = PTR_ERR(obj);
262 * Abstract function which parses path name. This function feeds
263 * path component to \a entry_func.
265 int dt_path_parser(const struct lu_env *env,
266 char *path, dt_entry_func_t entry_func,
273 e = strsep(&path, "/");
278 if (!path || path[0] == '\0')
282 rc = entry_func(env, e, data);
291 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
292 const char *path, struct lu_fid *fid)
294 struct dt_thread_info *info = dt_info(env);
295 struct dt_find_hint *dfh = &info->dti_dfh;
296 struct dt_object *obj;
303 strlcpy(info->dti_buf, path, sizeof(info->dti_buf));
305 result = dt->dd_ops->dt_root_get(env, dt, fid);
307 obj = dt_locate(env, dt, fid);
310 result = dt_path_parser(env, info->dti_buf,
313 obj = ERR_PTR(result);
318 obj = ERR_PTR(result);
323 static struct dt_object *dt_reg_open(const struct lu_env *env,
324 struct dt_device *dt,
332 result = dt_lookup_dir(env, p, name, fid);
334 o = dt_locate(env, dt, fid);
343 * Open dt object named \a filename from \a dirname directory.
344 * \param dt dt device
345 * \param fid on success, object fid is stored in *fid
347 struct dt_object *dt_store_open(const struct lu_env *env,
348 struct dt_device *dt,
350 const char *filename,
353 struct dt_object *file;
354 struct dt_object *dir;
356 dir = dt_store_resolve(env, dt, dirname, fid);
358 file = dt_reg_open(env, dt, dir,
360 lu_object_put(env, &dir->do_lu);
367 struct dt_object *dt_find_or_create(const struct lu_env *env,
368 struct dt_device *dt,
369 const struct lu_fid *fid,
370 struct dt_object_format *dof,
373 struct dt_object *dto;
379 dto = dt_locate(env, dt, fid);
383 LASSERT(dto != NULL);
384 if (dt_object_exists(dto))
387 th = dt_trans_create(env, dt);
389 GOTO(out, rc = PTR_ERR(th));
391 rc = dt_declare_create(env, dto, at, NULL, dof, th);
393 GOTO(trans_stop, rc);
395 rc = dt_trans_start_local(env, dt, th);
397 GOTO(trans_stop, rc);
399 dt_write_lock(env, dto, 0);
400 if (dt_object_exists(dto))
401 GOTO(unlock, rc = 0);
403 CDEBUG(D_OTHER, "create new object "DFID"\n", PFID(fid));
405 rc = dt_create(env, dto, at, NULL, dof, th);
408 LASSERT(dt_object_exists(dto));
410 dt_write_unlock(env, dto);
412 dt_trans_stop(env, dt, th);
415 lu_object_put(env, &dto->do_lu);
420 EXPORT_SYMBOL(dt_find_or_create);
422 /* dt class init function. */
423 int dt_global_init(void)
427 LU_CONTEXT_KEY_INIT(&dt_key);
428 result = lu_context_key_register(&dt_key);
432 void dt_global_fini(void)
434 lu_context_key_degister(&dt_key);
438 * Generic read helper. May return an error for partial reads.
440 * \param env lustre environment
441 * \param dt object to be read
442 * \param buf lu_buf to be filled, with buffer pointer and length
443 * \param pos position to start reading, updated as data is read
445 * \retval real size of data read
446 * \retval -ve errno on failure
448 int dt_read(const struct lu_env *env, struct dt_object *dt,
449 struct lu_buf *buf, loff_t *pos)
451 LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
452 return dt->do_body_ops->dbo_read(env, dt, buf, pos, BYPASS_CAPA);
454 EXPORT_SYMBOL(dt_read);
457 * Read structures of fixed size from storage. Unlike dt_read(), using
458 * dt_record_read() will return an error for partial reads.
460 * \param env lustre environment
461 * \param dt object to be read
462 * \param buf lu_buf to be filled, with buffer pointer and length
463 * \param pos position to start reading, updated as data is read
465 * \retval 0 on successfully reading full buffer
466 * \retval -EFAULT on short read
467 * \retval -ve errno on failure
469 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
470 struct lu_buf *buf, loff_t *pos)
474 LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
476 size = dt->do_body_ops->dbo_read(env, dt, buf, pos, BYPASS_CAPA);
480 return (size == (ssize_t)buf->lb_len) ? 0 : -EFAULT;
482 EXPORT_SYMBOL(dt_record_read);
484 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
485 const struct lu_buf *buf, loff_t *pos, struct thandle *th)
489 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
491 LASSERT(dt->do_body_ops);
492 LASSERT(dt->do_body_ops->dbo_write);
494 size = dt->do_body_ops->dbo_write(env, dt, buf, pos, th, BYPASS_CAPA, 1);
498 return (size == (ssize_t)buf->lb_len) ? 0 : -EFAULT;
500 EXPORT_SYMBOL(dt_record_write);
502 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
506 char *xname = XATTR_NAME_VERSION;
510 vbuf.lb_len = sizeof(dt_obj_version_t);
511 return dt_declare_xattr_set(env, o, &vbuf, xname, 0, th);
514 EXPORT_SYMBOL(dt_declare_version_set);
516 void dt_version_set(const struct lu_env *env, struct dt_object *o,
517 dt_obj_version_t version, struct thandle *th)
520 char *xname = XATTR_NAME_VERSION;
524 vbuf.lb_buf = &version;
525 vbuf.lb_len = sizeof(version);
527 rc = dt_xattr_set(env, o, &vbuf, xname, 0, th, BYPASS_CAPA);
529 CDEBUG(D_INODE, "Can't set version, rc %d\n", rc);
532 EXPORT_SYMBOL(dt_version_set);
534 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o)
537 char *xname = XATTR_NAME_VERSION;
538 dt_obj_version_t version;
542 vbuf.lb_buf = &version;
543 vbuf.lb_len = sizeof(version);
544 rc = dt_xattr_get(env, o, &vbuf, xname, BYPASS_CAPA);
545 if (rc != sizeof(version)) {
546 CDEBUG(D_INODE, "Can't get version, rc %d\n", rc);
551 EXPORT_SYMBOL(dt_version_get);
553 /* list of all supported index types */
556 const struct dt_index_features dt_directory_features;
557 EXPORT_SYMBOL(dt_directory_features);
560 const struct dt_index_features dt_otable_features;
561 EXPORT_SYMBOL(dt_otable_features);
564 const struct dt_index_features dt_lfsck_orphan_features = {
566 .dif_keysize_min = sizeof(struct lu_fid),
567 .dif_keysize_max = sizeof(struct lu_fid),
568 .dif_recsize_min = sizeof(struct lu_orphan_rec),
569 .dif_recsize_max = sizeof(struct lu_orphan_rec),
572 EXPORT_SYMBOL(dt_lfsck_orphan_features);
575 const struct dt_index_features dt_lfsck_features = {
576 .dif_flags = DT_IND_UPDATE,
577 .dif_keysize_min = sizeof(struct lu_fid),
578 .dif_keysize_max = sizeof(struct lu_fid),
579 .dif_recsize_min = sizeof(__u8),
580 .dif_recsize_max = sizeof(__u8),
583 EXPORT_SYMBOL(dt_lfsck_features);
585 /* accounting indexes */
586 const struct dt_index_features dt_acct_features = {
587 .dif_flags = DT_IND_UPDATE,
588 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
589 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
590 .dif_recsize_min = sizeof(struct lquota_acct_rec), /* 16 bytes */
591 .dif_recsize_max = sizeof(struct lquota_acct_rec), /* 16 bytes */
594 EXPORT_SYMBOL(dt_acct_features);
596 /* global quota files */
597 const struct dt_index_features dt_quota_glb_features = {
598 .dif_flags = DT_IND_UPDATE,
599 /* a different key would have to be used for per-directory quota */
600 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
601 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
602 .dif_recsize_min = sizeof(struct lquota_glb_rec), /* 32 bytes */
603 .dif_recsize_max = sizeof(struct lquota_glb_rec), /* 32 bytes */
606 EXPORT_SYMBOL(dt_quota_glb_features);
608 /* slave quota files */
609 const struct dt_index_features dt_quota_slv_features = {
610 .dif_flags = DT_IND_UPDATE,
611 /* a different key would have to be used for per-directory quota */
612 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
613 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
614 .dif_recsize_min = sizeof(struct lquota_slv_rec), /* 8 bytes */
615 .dif_recsize_max = sizeof(struct lquota_slv_rec), /* 8 bytes */
618 EXPORT_SYMBOL(dt_quota_slv_features);
620 /* helper function returning what dt_index_features structure should be used
621 * based on the FID sequence. This is used by OBD_IDX_READ RPC */
622 static inline const struct dt_index_features *dt_index_feat_select(__u64 seq,
625 if (seq == FID_SEQ_QUOTA_GLB) {
626 /* global quota index */
628 /* global quota index should be a regular file */
629 return ERR_PTR(-ENOENT);
630 return &dt_quota_glb_features;
631 } else if (seq == FID_SEQ_QUOTA) {
632 /* quota slave index */
634 /* slave index should be a regular file */
635 return ERR_PTR(-ENOENT);
636 return &dt_quota_slv_features;
637 } else if (seq == FID_SEQ_LAYOUT_RBTREE){
638 return &dt_lfsck_orphan_features;
639 } else if (seq >= FID_SEQ_NORMAL) {
640 /* object is part of the namespace, verify that it is a
643 /* sorry, we can only deal with directory */
644 return ERR_PTR(-ENOTDIR);
645 return &dt_directory_features;
648 return ERR_PTR(-EOPNOTSUPP);
652 * Fill a lu_idxpage with key/record pairs read for transfer via OBD_IDX_READ
655 * \param env - is the environment passed by the caller
656 * \param lp - is a pointer to the lu_page to fill
657 * \param nob - is the maximum number of bytes that should be copied
658 * \param iops - is the index operation vector associated with the index object
659 * \param it - is a pointer to the current iterator
660 * \param attr - is the index attribute to pass to iops->rec()
661 * \param arg - is a pointer to the idx_info structure
663 static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
664 size_t nob, const struct dt_it_ops *iops,
665 struct dt_it *it, __u32 attr, void *arg)
667 struct idx_info *ii = (struct idx_info *)arg;
668 struct lu_idxpage *lip = &lp->lp_idx;
674 if (nob < LIP_HDR_SIZE)
677 /* initialize the header of the new container */
678 memset(lip, 0, LIP_HDR_SIZE);
679 lip->lip_magic = LIP_MAGIC;
682 /* compute size needed to store a key/record pair */
683 size = ii->ii_recsize + ii->ii_keysize;
684 if ((ii->ii_flags & II_FL_NOHASH) == 0)
685 /* add hash if the client wants it */
686 size += sizeof(__u64);
688 entry = lip->lip_entries;
690 char *tmp_entry = entry;
696 /* fetch 64-bit hash value */
697 hash = iops->store(env, it);
698 ii->ii_hash_end = hash;
700 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_IDX_READ_BREAK)) {
701 if (lip->lip_nr != 0)
706 if (lip->lip_nr == 0)
707 GOTO(out, rc = -EINVAL);
711 if (!(ii->ii_flags & II_FL_NOHASH)) {
712 /* client wants to the 64-bit hash value associated with
714 memcpy(tmp_entry, &hash, sizeof(hash));
715 tmp_entry += sizeof(hash);
718 if (ii->ii_flags & II_FL_VARKEY)
719 keysize = iops->key_size(env, it);
721 keysize = ii->ii_keysize;
723 if (!(ii->ii_flags & II_FL_NOKEY)) {
724 /* then the key value */
725 key = iops->key(env, it);
726 memcpy(tmp_entry, key, keysize);
727 tmp_entry += keysize;
730 /* and finally the record */
731 rc = iops->rec(env, it, (struct dt_rec *)tmp_entry, attr);
736 /* hash/key/record successfully copied! */
738 if (unlikely(lip->lip_nr == 1 && ii->ii_count == 0))
739 ii->ii_hash_start = hash;
741 if (ii->ii_flags & II_FL_VARREC)
742 recsize = iops->rec_size(env, it, attr);
744 recsize = ii->ii_recsize;
746 entry = tmp_entry + recsize;
750 /* move on to the next record */
752 rc = iops->next(env, it);
753 } while (rc == -ESTALE);
759 if (rc >= 0 && lip->lip_nr > 0)
760 /* one more container */
763 /* no more entries */
764 ii->ii_hash_end = II_END_OFF;
770 * Walk index and fill lu_page containers with key/record pairs
772 * \param env - is the environment passed by the caller
773 * \param obj - is the index object to parse
774 * \param rdpg - is the lu_rdpg descriptor associated with the transfer
775 * \param filler - is the callback function responsible for filling a lu_page
776 * with key/record pairs in the format wanted by the caller
777 * \param arg - is an opaq argument passed to the filler function
779 * \retval sum (in bytes) of all filled lu_pages
780 * \retval -ve errno on failure
782 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
783 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
787 const struct dt_it_ops *iops;
788 size_t pageidx, nob, nlupgs = 0;
792 LASSERT(rdpg->rp_pages != NULL);
793 LASSERT(obj->do_index_ops != NULL);
795 nob = rdpg->rp_count;
799 /* Iterate through index and fill containers from @rdpg */
800 iops = &obj->do_index_ops->dio_it;
801 LASSERT(iops != NULL);
802 it = iops->init(env, obj, rdpg->rp_attrs, BYPASS_CAPA);
806 rc = iops->load(env, it, rdpg->rp_hash);
809 * Iterator didn't find record with exactly the key requested.
811 * It is currently either
813 * - positioned above record with key less than
814 * requested---skip it.
815 * - or not positioned at all (is in IAM_IT_SKEWED
816 * state)---position it on the next item.
818 rc = iops->next(env, it);
827 /* Fill containers one after the other. There might be multiple
828 * containers per physical page.
830 * At this point and across for-loop:
831 * rc == 0 -> ok, proceed.
832 * rc > 0 -> end of index.
833 * rc < 0 -> error. */
834 for (pageidx = 0; rc == 0 && nob > 0; pageidx++) {
838 LASSERT(pageidx < rdpg->rp_npages);
839 lp = kmap(rdpg->rp_pages[pageidx]);
842 for (i = 0; i < LU_PAGE_COUNT; i++, lp++, nob -= LU_PAGE_SIZE) {
843 rc = filler(env, lp, min_t(size_t, nob, LU_PAGE_SIZE),
844 iops, it, rdpg->rp_attrs, arg);
847 /* one more lu_page */
853 kunmap(rdpg->rp_pages[i]);
861 rc = min_t(size_t, nlupgs * LU_PAGE_SIZE, rdpg->rp_count);
865 EXPORT_SYMBOL(dt_index_walk);
868 * Walk key/record pairs of an index and copy them into 4KB containers to be
869 * transferred over the network. This is the common handler for OBD_IDX_READ
872 * \param env - is the environment passed by the caller
873 * \param dev - is the dt_device storing the index
874 * \param ii - is the idx_info structure packed by the client in the
875 * OBD_IDX_READ request
876 * \param rdpg - is the lu_rdpg descriptor
878 * \retval on success, return sum (in bytes) of all filled containers
879 * \retval appropriate error otherwise.
881 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
882 struct idx_info *ii, const struct lu_rdpg *rdpg)
884 const struct dt_index_features *feat;
885 struct dt_object *obj;
889 /* rp_count shouldn't be null and should be a multiple of the container
891 if (rdpg->rp_count == 0 || (rdpg->rp_count & (LU_PAGE_SIZE - 1)) != 0)
894 if (!fid_is_quota(&ii->ii_fid) && !fid_is_layout_rbtree(&ii->ii_fid) &&
895 !fid_is_norm(&ii->ii_fid))
898 /* lookup index object subject to the transfer */
899 obj = dt_locate(env, dev, &ii->ii_fid);
901 RETURN(PTR_ERR(obj));
902 if (dt_object_exists(obj) == 0)
903 GOTO(out, rc = -ENOENT);
905 /* fetch index features associated with index object */
906 feat = dt_index_feat_select(fid_seq(&ii->ii_fid),
907 lu_object_attr(&obj->do_lu));
909 GOTO(out, rc = PTR_ERR(feat));
911 /* load index feature if not done already */
912 if (obj->do_index_ops == NULL) {
913 rc = obj->do_ops->do_index_try(env, obj, feat);
918 /* fill ii_flags with supported index features */
919 ii->ii_flags &= (II_FL_NOHASH | II_FL_NOKEY | II_FL_VARKEY |
922 if (!(feat->dif_flags & DT_IND_VARKEY))
923 ii->ii_keysize = feat->dif_keysize_max;
925 if (!(feat->dif_flags & DT_IND_VARREC))
926 ii->ii_recsize = feat->dif_recsize_max;
928 if (feat->dif_flags & DT_IND_NONUNQ)
929 /* key isn't necessarily unique */
930 ii->ii_flags |= II_FL_NONUNQ;
932 if (!fid_is_layout_rbtree(&ii->ii_fid)) {
933 dt_read_lock(env, obj, 0);
934 /* fetch object version before walking the index */
935 ii->ii_version = dt_version_get(env, obj);
938 /* walk the index and fill lu_idxpages with key/record pairs */
939 rc = dt_index_walk(env, obj, rdpg, dt_index_page_build, ii);
940 if (!fid_is_layout_rbtree(&ii->ii_fid))
941 dt_read_unlock(env, obj);
945 LASSERT(ii->ii_count == 0);
946 ii->ii_hash_end = II_END_OFF;
951 lu_object_put(env, &obj->do_lu);
954 EXPORT_SYMBOL(dt_index_read);
956 #ifdef CONFIG_PROC_FS
957 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v)
959 struct dt_device *dt = m->private;
960 struct obd_statfs osfs;
962 int rc = dt_statfs(NULL, dt, &osfs);
964 seq_printf(m, "%u\n", (unsigned) osfs.os_bsize);
967 EXPORT_SYMBOL(lprocfs_dt_blksize_seq_show);
969 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v)
971 struct dt_device *dt = m->private;
972 struct obd_statfs osfs;
974 int rc = dt_statfs(NULL, dt, &osfs);
976 __u32 blk_size = osfs.os_bsize >> 10;
977 __u64 result = osfs.os_blocks;
979 while (blk_size >>= 1)
982 seq_printf(m, LPU64"\n", result);
986 EXPORT_SYMBOL(lprocfs_dt_kbytestotal_seq_show);
988 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v)
990 struct dt_device *dt = m->private;
991 struct obd_statfs osfs;
993 int rc = dt_statfs(NULL, dt, &osfs);
995 __u32 blk_size = osfs.os_bsize >> 10;
996 __u64 result = osfs.os_bfree;
998 while (blk_size >>= 1)
1001 seq_printf(m, LPU64"\n", result);
1005 EXPORT_SYMBOL(lprocfs_dt_kbytesfree_seq_show);
1007 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v)
1009 struct dt_device *dt = m->private;
1010 struct obd_statfs osfs;
1012 int rc = dt_statfs(NULL, dt, &osfs);
1014 __u32 blk_size = osfs.os_bsize >> 10;
1015 __u64 result = osfs.os_bavail;
1017 while (blk_size >>= 1)
1020 seq_printf(m, LPU64"\n", result);
1024 EXPORT_SYMBOL(lprocfs_dt_kbytesavail_seq_show);
1026 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v)
1028 struct dt_device *dt = m->private;
1029 struct obd_statfs osfs;
1031 int rc = dt_statfs(NULL, dt, &osfs);
1033 seq_printf(m, LPU64"\n", osfs.os_files);
1036 EXPORT_SYMBOL(lprocfs_dt_filestotal_seq_show);
1038 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v)
1040 struct dt_device *dt = m->private;
1041 struct obd_statfs osfs;
1043 int rc = dt_statfs(NULL, dt, &osfs);
1045 seq_printf(m, LPU64"\n", osfs.os_ffree);
1048 EXPORT_SYMBOL(lprocfs_dt_filesfree_seq_show);
1050 #endif /* CONFIG_PROC_FS */