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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/obdclass/dt_object.c
35 * Generic functions from dt_object.h
37 * Author: Nikita Danilov <nikita@clusterfs.com>
40 #define DEBUG_SUBSYSTEM S_CLASS
42 #include <linux/list.h>
44 #include <dt_object.h>
46 #include <lustre_fid.h>
47 #include <lustre_nodemap.h>
48 #include <lustre_quota.h>
50 /* context key constructor/destructor: dt_global_key_init, dt_global_key_fini */
51 LU_KEY_INIT(dt_global, struct dt_thread_info);
52 LU_KEY_FINI(dt_global, struct dt_thread_info);
54 struct lu_context_key dt_key = {
55 .lct_tags = LCT_MD_THREAD | LCT_DT_THREAD | LCT_MG_THREAD | LCT_LOCAL,
56 .lct_init = dt_global_key_init,
57 .lct_fini = dt_global_key_fini
60 /* no lock is necessary to protect the list, because call-backs
61 * are added during system startup. Please refer to "struct dt_device".
63 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb)
65 list_add(&cb->dtc_linkage, &dev->dd_txn_callbacks);
67 EXPORT_SYMBOL(dt_txn_callback_add);
69 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb)
71 list_del_init(&cb->dtc_linkage);
73 EXPORT_SYMBOL(dt_txn_callback_del);
75 int dt_txn_hook_start(const struct lu_env *env,
76 struct dt_device *dev, struct thandle *th)
79 struct dt_txn_callback *cb;
84 list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
85 struct thandle *dtc_th = th;
87 if (cb->dtc_txn_start == NULL ||
88 !(cb->dtc_tag & env->le_ctx.lc_tags))
91 /* Usually dt_txn_hook_start is called from bottom device,
92 * and if the thandle has th_top, then we need use top
93 * thandle for the callback in the top thandle layer */
94 if (th->th_top != NULL)
97 rc = cb->dtc_txn_start(env, dtc_th, cb->dtc_cookie);
103 EXPORT_SYMBOL(dt_txn_hook_start);
105 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *th)
107 struct dt_device *dev = th->th_dev;
108 struct dt_txn_callback *cb;
114 if (OBD_FAIL_CHECK(OBD_FAIL_DT_TXN_STOP))
117 list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
118 struct thandle *dtc_th = th;
120 if (cb->dtc_txn_stop == NULL ||
121 !(cb->dtc_tag & env->le_ctx.lc_tags))
124 /* Usually dt_txn_hook_stop is called from bottom device,
125 * and if the thandle has th_top, then we need use top
126 * thandle for the callback in the top thandle layer */
127 if (th->th_top != NULL)
130 rc = cb->dtc_txn_stop(env, dtc_th, cb->dtc_cookie);
136 EXPORT_SYMBOL(dt_txn_hook_stop);
138 void dt_txn_hook_commit(struct thandle *th)
140 struct dt_txn_callback *cb;
145 list_for_each_entry(cb, &th->th_dev->dd_txn_callbacks,
147 /* Right now, the bottom device (OSD) will use this hook
148 * commit to notify OSP, so we do not check and replace
149 * the thandle to top thandle now */
150 if (cb->dtc_txn_commit)
151 cb->dtc_txn_commit(th, cb->dtc_cookie);
154 EXPORT_SYMBOL(dt_txn_hook_commit);
156 int dt_device_init(struct dt_device *dev, struct lu_device_type *t)
158 INIT_LIST_HEAD(&dev->dd_txn_callbacks);
159 return lu_device_init(&dev->dd_lu_dev, t);
161 EXPORT_SYMBOL(dt_device_init);
163 void dt_device_fini(struct dt_device *dev)
165 lu_device_fini(&dev->dd_lu_dev);
167 EXPORT_SYMBOL(dt_device_fini);
169 int dt_object_init(struct dt_object *obj,
170 struct lu_object_header *h, struct lu_device *d)
173 return lu_object_init(&obj->do_lu, h, d);
175 EXPORT_SYMBOL(dt_object_init);
177 void dt_object_fini(struct dt_object *obj)
179 lu_object_fini(&obj->do_lu);
181 EXPORT_SYMBOL(dt_object_fini);
183 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj)
185 if (obj->do_index_ops == NULL)
186 obj->do_ops->do_index_try(env, obj, &dt_directory_features);
187 return obj->do_index_ops != NULL;
189 EXPORT_SYMBOL(dt_try_as_dir);
191 enum dt_format_type dt_mode_to_dft(__u32 mode)
193 enum dt_format_type result;
195 switch (mode & S_IFMT) {
200 result = DFT_REGULAR;
217 EXPORT_SYMBOL(dt_mode_to_dft);
220 * lookup fid for object named \a name in directory \a dir.
223 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
224 const char *name, struct lu_fid *fid)
226 if (dt_try_as_dir(env, dir))
227 return dt_lookup(env, dir, (struct dt_rec *)fid,
228 (const struct dt_key *)name);
231 EXPORT_SYMBOL(dt_lookup_dir);
233 /* this differs from dt_locate by top_dev as parameter
234 * but not one from lu_site */
235 struct dt_object *dt_locate_at(const struct lu_env *env,
236 struct dt_device *dev,
237 const struct lu_fid *fid,
238 struct lu_device *top_dev,
239 const struct lu_object_conf *conf)
241 struct lu_object *lo;
244 lo = lu_object_find_at(env, top_dev, fid, conf);
246 return ERR_PTR(PTR_ERR(lo));
250 list_for_each_entry(n, &lo->lo_header->loh_layers, lo_linkage) {
251 if (n->lo_dev == &dev->dd_lu_dev)
252 return container_of0(n, struct dt_object, do_lu);
255 return ERR_PTR(-ENOENT);
257 EXPORT_SYMBOL(dt_locate_at);
260 * find an object named \a entry in given \a dfh->dfh_o directory.
262 static int dt_find_entry(const struct lu_env *env, const char *entry,
265 struct dt_find_hint *dfh = data;
266 struct dt_device *dt = dfh->dfh_dt;
267 struct lu_fid *fid = dfh->dfh_fid;
268 struct dt_object *obj = dfh->dfh_o;
271 rc = dt_lookup_dir(env, obj, entry, fid);
272 dt_object_put(env, obj);
274 obj = dt_locate(env, dt, fid);
284 * Abstract function which parses path name. This function feeds
285 * path component to \a entry_func.
287 int dt_path_parser(const struct lu_env *env,
288 char *path, dt_entry_func_t entry_func,
295 e = strsep(&path, "/");
300 if (!path || path[0] == '\0')
304 rc = entry_func(env, e, data);
313 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
314 const char *path, struct lu_fid *fid)
316 struct dt_thread_info *info = dt_info(env);
317 struct dt_find_hint *dfh = &info->dti_dfh;
318 struct dt_object *obj;
325 strlcpy(info->dti_buf, path, sizeof(info->dti_buf));
327 result = dt->dd_ops->dt_root_get(env, dt, fid);
329 obj = dt_locate(env, dt, fid);
332 result = dt_path_parser(env, info->dti_buf,
335 obj = ERR_PTR(result);
340 obj = ERR_PTR(result);
345 static struct dt_object *dt_reg_open(const struct lu_env *env,
346 struct dt_device *dt,
354 result = dt_lookup_dir(env, p, name, fid);
356 o = dt_locate(env, dt, fid);
365 * Open dt object named \a filename from \a dirname directory.
366 * \param dt dt device
367 * \param fid on success, object fid is stored in *fid
369 struct dt_object *dt_store_open(const struct lu_env *env, struct dt_device *dt,
370 const char *dirname, const char *filename,
373 struct dt_object *file;
374 struct dt_object *dir;
376 dir = dt_store_resolve(env, dt, dirname, fid);
378 file = dt_reg_open(env, dt, dir, filename, fid);
379 dt_object_put(env, dir);
387 struct dt_object *dt_find_or_create(const struct lu_env *env,
388 struct dt_device *dt,
389 const struct lu_fid *fid,
390 struct dt_object_format *dof,
393 struct dt_object *dto;
399 dto = dt_locate(env, dt, fid);
403 LASSERT(dto != NULL);
404 if (dt_object_exists(dto))
407 th = dt_trans_create(env, dt);
409 GOTO(out, rc = PTR_ERR(th));
411 rc = dt_declare_create(env, dto, at, NULL, dof, th);
413 GOTO(trans_stop, rc);
415 rc = dt_trans_start_local(env, dt, th);
417 GOTO(trans_stop, rc);
419 dt_write_lock(env, dto, 0);
420 if (dt_object_exists(dto))
421 GOTO(unlock, rc = 0);
423 CDEBUG(D_OTHER, "create new object "DFID"\n", PFID(fid));
425 rc = dt_create(env, dto, at, NULL, dof, th);
428 LASSERT(dt_object_exists(dto));
430 dt_write_unlock(env, dto);
432 dt_trans_stop(env, dt, th);
435 dt_object_put(env, dto);
441 EXPORT_SYMBOL(dt_find_or_create);
443 /* dt class init function. */
444 int dt_global_init(void)
448 LU_CONTEXT_KEY_INIT(&dt_key);
449 result = lu_context_key_register(&dt_key);
453 void dt_global_fini(void)
455 lu_context_key_degister(&dt_key);
459 * Generic read helper. May return an error for partial reads.
461 * \param env lustre environment
462 * \param dt object to be read
463 * \param buf lu_buf to be filled, with buffer pointer and length
464 * \param pos position to start reading, updated as data is read
466 * \retval real size of data read
467 * \retval -ve errno on failure
469 int dt_read(const struct lu_env *env, struct dt_object *dt,
470 struct lu_buf *buf, loff_t *pos)
472 LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
473 return dt->do_body_ops->dbo_read(env, dt, buf, pos);
475 EXPORT_SYMBOL(dt_read);
478 * Read structures of fixed size from storage. Unlike dt_read(), using
479 * dt_record_read() will return an error for partial reads.
481 * \param env lustre environment
482 * \param dt object to be read
483 * \param buf lu_buf to be filled, with buffer pointer and length
484 * \param pos position to start reading, updated as data is read
486 * \retval 0 on successfully reading full buffer
487 * \retval -EFAULT on short read
488 * \retval -ve errno on failure
490 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
491 struct lu_buf *buf, loff_t *pos)
495 LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
497 size = dt->do_body_ops->dbo_read(env, dt, buf, pos);
500 return (size == (ssize_t)buf->lb_len) ? 0 : -EFAULT;
502 EXPORT_SYMBOL(dt_record_read);
504 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
505 const struct lu_buf *buf, loff_t *pos, struct thandle *th)
509 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
511 LASSERT(dt->do_body_ops);
512 LASSERT(dt->do_body_ops->dbo_write);
514 size = dt->do_body_ops->dbo_write(env, dt, buf, pos, th, 1);
517 return (size == (ssize_t)buf->lb_len) ? 0 : -EFAULT;
519 EXPORT_SYMBOL(dt_record_write);
521 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
525 char *xname = XATTR_NAME_VERSION;
529 vbuf.lb_len = sizeof(dt_obj_version_t);
530 return dt_declare_xattr_set(env, o, &vbuf, xname, 0, th);
533 EXPORT_SYMBOL(dt_declare_version_set);
535 void dt_version_set(const struct lu_env *env, struct dt_object *o,
536 dt_obj_version_t version, struct thandle *th)
539 char *xname = XATTR_NAME_VERSION;
543 vbuf.lb_buf = &version;
544 vbuf.lb_len = sizeof(version);
546 rc = dt_xattr_set(env, o, &vbuf, xname, 0, th);
548 CDEBUG(D_INODE, "Can't set version, rc %d\n", rc);
551 EXPORT_SYMBOL(dt_version_set);
553 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o)
556 char *xname = XATTR_NAME_VERSION;
557 dt_obj_version_t version;
561 vbuf.lb_buf = &version;
562 vbuf.lb_len = sizeof(version);
563 rc = dt_xattr_get(env, o, &vbuf, xname);
564 if (rc != sizeof(version)) {
565 CDEBUG(D_INODE, "Can't get version, rc %d\n", rc);
570 EXPORT_SYMBOL(dt_version_get);
572 /* list of all supported index types */
575 const struct dt_index_features dt_directory_features;
576 EXPORT_SYMBOL(dt_directory_features);
579 const struct dt_index_features dt_otable_features;
580 EXPORT_SYMBOL(dt_otable_features);
582 /* lfsck layout orphan */
583 const struct dt_index_features dt_lfsck_layout_orphan_features = {
585 .dif_keysize_min = sizeof(struct lu_fid),
586 .dif_keysize_max = sizeof(struct lu_fid),
587 .dif_recsize_min = sizeof(struct lu_orphan_rec),
588 .dif_recsize_max = sizeof(struct lu_orphan_rec),
591 EXPORT_SYMBOL(dt_lfsck_layout_orphan_features);
593 /* lfsck layout dangling */
594 const struct dt_index_features dt_lfsck_layout_dangling_features = {
595 .dif_flags = DT_IND_UPDATE,
596 .dif_keysize_min = sizeof(struct lu_fid),
597 .dif_keysize_max = sizeof(struct lu_fid),
598 .dif_recsize_min = sizeof(struct lu_fid),
599 .dif_recsize_max = sizeof(struct lu_fid),
602 EXPORT_SYMBOL(dt_lfsck_layout_dangling_features);
604 /* lfsck namespace */
605 const struct dt_index_features dt_lfsck_namespace_features = {
606 .dif_flags = DT_IND_UPDATE,
607 .dif_keysize_min = sizeof(struct lu_fid),
608 .dif_keysize_max = sizeof(struct lu_fid),
609 .dif_recsize_min = sizeof(__u8),
610 .dif_recsize_max = sizeof(__u8),
613 EXPORT_SYMBOL(dt_lfsck_namespace_features);
615 /* accounting indexes */
616 const struct dt_index_features dt_acct_features = {
617 .dif_flags = DT_IND_UPDATE,
618 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
619 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
620 .dif_recsize_min = sizeof(struct lquota_acct_rec), /* 16 bytes */
621 .dif_recsize_max = sizeof(struct lquota_acct_rec), /* 16 bytes */
624 EXPORT_SYMBOL(dt_acct_features);
626 /* global quota files */
627 const struct dt_index_features dt_quota_glb_features = {
628 .dif_flags = DT_IND_UPDATE,
629 /* a different key would have to be used for per-directory quota */
630 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
631 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
632 .dif_recsize_min = sizeof(struct lquota_glb_rec), /* 32 bytes */
633 .dif_recsize_max = sizeof(struct lquota_glb_rec), /* 32 bytes */
636 EXPORT_SYMBOL(dt_quota_glb_features);
638 /* slave quota files */
639 const struct dt_index_features dt_quota_slv_features = {
640 .dif_flags = DT_IND_UPDATE,
641 /* a different key would have to be used for per-directory quota */
642 .dif_keysize_min = sizeof(__u64), /* 64-bit uid/gid */
643 .dif_keysize_max = sizeof(__u64), /* 64-bit uid/gid */
644 .dif_recsize_min = sizeof(struct lquota_slv_rec), /* 8 bytes */
645 .dif_recsize_max = sizeof(struct lquota_slv_rec), /* 8 bytes */
648 EXPORT_SYMBOL(dt_quota_slv_features);
650 /* nodemap files, nodemap_rec size asserted in nodemap_storage.c */
651 const struct dt_index_features dt_nodemap_features = {
652 .dif_flags = DT_IND_UPDATE,
653 .dif_keysize_min = sizeof(__u64), /* 64-bit nodemap/record id */
654 .dif_keysize_max = sizeof(__u64), /* 64-bit nodemap/record id */
655 .dif_recsize_min = sizeof(union nodemap_rec), /* 32 bytes */
656 .dif_recsize_max = sizeof(union nodemap_rec), /* 32 bytes */
659 EXPORT_SYMBOL(dt_nodemap_features);
661 /* helper function returning what dt_index_features structure should be used
662 * based on the FID sequence. This is used by OBD_IDX_READ RPC */
663 static inline const struct dt_index_features *dt_index_feat_select(__u64 seq,
666 if (seq == FID_SEQ_QUOTA_GLB) {
667 /* global quota index */
669 /* global quota index should be a regular file */
670 return ERR_PTR(-ENOENT);
671 return &dt_quota_glb_features;
672 } else if (seq == FID_SEQ_QUOTA) {
673 /* quota slave index */
675 /* slave index should be a regular file */
676 return ERR_PTR(-ENOENT);
677 return &dt_quota_slv_features;
678 } else if (seq == FID_SEQ_LAYOUT_RBTREE){
679 return &dt_lfsck_layout_orphan_features;
680 } else if (seq >= FID_SEQ_NORMAL) {
681 /* object is part of the namespace, verify that it is a
684 /* sorry, we can only deal with directory */
685 return ERR_PTR(-ENOTDIR);
686 return &dt_directory_features;
689 return ERR_PTR(-EOPNOTSUPP);
693 * Fill a lu_idxpage with key/record pairs read for transfer via OBD_IDX_READ
696 * \param env - is the environment passed by the caller
697 * \param lp - is a pointer to the lu_page to fill
698 * \param nob - is the maximum number of bytes that should be copied
699 * \param iops - is the index operation vector associated with the index object
700 * \param it - is a pointer to the current iterator
701 * \param attr - is the index attribute to pass to iops->rec()
702 * \param arg - is a pointer to the idx_info structure
704 static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
705 size_t nob, const struct dt_it_ops *iops,
706 struct dt_it *it, __u32 attr, void *arg)
708 struct idx_info *ii = (struct idx_info *)arg;
709 struct lu_idxpage *lip = &lp->lp_idx;
715 if (nob < LIP_HDR_SIZE)
718 /* initialize the header of the new container */
719 memset(lip, 0, LIP_HDR_SIZE);
720 lip->lip_magic = LIP_MAGIC;
723 /* compute size needed to store a key/record pair */
724 size = ii->ii_recsize + ii->ii_keysize;
725 if ((ii->ii_flags & II_FL_NOHASH) == 0)
726 /* add hash if the client wants it */
727 size += sizeof(__u64);
729 entry = lip->lip_entries;
731 char *tmp_entry = entry;
737 /* fetch 64-bit hash value */
738 hash = iops->store(env, it);
739 ii->ii_hash_end = hash;
741 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_IDX_READ_BREAK)) {
742 if (lip->lip_nr != 0)
747 if (lip->lip_nr == 0)
748 GOTO(out, rc = -EINVAL);
752 if (!(ii->ii_flags & II_FL_NOHASH)) {
753 /* client wants to the 64-bit hash value associated with
755 memcpy(tmp_entry, &hash, sizeof(hash));
756 tmp_entry += sizeof(hash);
759 if (ii->ii_flags & II_FL_VARKEY)
760 keysize = iops->key_size(env, it);
762 keysize = ii->ii_keysize;
764 if (!(ii->ii_flags & II_FL_NOKEY)) {
765 /* then the key value */
766 key = iops->key(env, it);
767 memcpy(tmp_entry, key, keysize);
768 tmp_entry += keysize;
771 /* and finally the record */
772 rc = iops->rec(env, it, (struct dt_rec *)tmp_entry, attr);
777 /* hash/key/record successfully copied! */
779 if (unlikely(lip->lip_nr == 1 && ii->ii_count == 0))
780 ii->ii_hash_start = hash;
782 if (ii->ii_flags & II_FL_VARREC)
783 recsize = iops->rec_size(env, it, attr);
785 recsize = ii->ii_recsize;
787 entry = tmp_entry + recsize;
791 /* move on to the next record */
793 rc = iops->next(env, it);
794 } while (rc == -ESTALE);
800 if (rc >= 0 && lip->lip_nr > 0)
801 /* one more container */
804 /* no more entries */
805 ii->ii_hash_end = II_END_OFF;
811 * Walk index and fill lu_page containers with key/record pairs
813 * \param env - is the environment passed by the caller
814 * \param obj - is the index object to parse
815 * \param rdpg - is the lu_rdpg descriptor associated with the transfer
816 * \param filler - is the callback function responsible for filling a lu_page
817 * with key/record pairs in the format wanted by the caller.
818 * If NULL, uses dt_index_page_build
819 * \param arg - is an opaq argument passed to the filler function
821 * \retval sum (in bytes) of all filled lu_pages
822 * \retval -ve errno on failure
824 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
825 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
829 const struct dt_it_ops *iops;
830 size_t pageidx, nob, nlupgs = 0;
834 LASSERT(rdpg->rp_pages != NULL);
835 LASSERT(obj->do_index_ops != NULL);
838 filler = dt_index_page_build;
840 nob = rdpg->rp_count;
844 /* Iterate through index and fill containers from @rdpg */
845 iops = &obj->do_index_ops->dio_it;
846 LASSERT(iops != NULL);
847 it = iops->init(env, obj, rdpg->rp_attrs);
851 rc = iops->load(env, it, rdpg->rp_hash);
854 * Iterator didn't find record with exactly the key requested.
856 * It is currently either
858 * - positioned above record with key less than
859 * requested---skip it.
860 * - or not positioned at all (is in IAM_IT_SKEWED
861 * state)---position it on the next item.
863 rc = iops->next(env, it);
872 /* Fill containers one after the other. There might be multiple
873 * containers per physical page.
875 * At this point and across for-loop:
876 * rc == 0 -> ok, proceed.
877 * rc > 0 -> end of index.
878 * rc < 0 -> error. */
879 for (pageidx = 0; rc == 0 && nob > 0; pageidx++) {
883 LASSERT(pageidx < rdpg->rp_npages);
884 lp = kmap(rdpg->rp_pages[pageidx]);
887 for (i = 0; i < LU_PAGE_COUNT; i++, lp++, nob -= LU_PAGE_SIZE) {
888 rc = filler(env, lp, min_t(size_t, nob, LU_PAGE_SIZE),
889 iops, it, rdpg->rp_attrs, arg);
892 /* one more lu_page */
898 kunmap(rdpg->rp_pages[i]);
906 rc = min_t(size_t, nlupgs * LU_PAGE_SIZE, rdpg->rp_count);
910 EXPORT_SYMBOL(dt_index_walk);
913 * Walk key/record pairs of an index and copy them into 4KB containers to be
914 * transferred over the network. This is the common handler for OBD_IDX_READ
917 * \param env - is the environment passed by the caller
918 * \param dev - is the dt_device storing the index
919 * \param ii - is the idx_info structure packed by the client in the
920 * OBD_IDX_READ request
921 * \param rdpg - is the lu_rdpg descriptor
923 * \retval on success, return sum (in bytes) of all filled containers
924 * \retval appropriate error otherwise.
926 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
927 struct idx_info *ii, const struct lu_rdpg *rdpg)
929 const struct dt_index_features *feat;
930 struct dt_object *obj;
934 /* rp_count shouldn't be null and should be a multiple of the container
936 if (rdpg->rp_count == 0 || (rdpg->rp_count & (LU_PAGE_SIZE - 1)) != 0)
939 if (!fid_is_quota(&ii->ii_fid) && !fid_is_layout_rbtree(&ii->ii_fid) &&
940 !fid_is_norm(&ii->ii_fid))
943 /* lookup index object subject to the transfer */
944 obj = dt_locate(env, dev, &ii->ii_fid);
946 RETURN(PTR_ERR(obj));
947 if (dt_object_exists(obj) == 0)
948 GOTO(out, rc = -ENOENT);
950 /* fetch index features associated with index object */
951 feat = dt_index_feat_select(fid_seq(&ii->ii_fid),
952 lu_object_attr(&obj->do_lu));
954 GOTO(out, rc = PTR_ERR(feat));
956 /* load index feature if not done already */
957 if (obj->do_index_ops == NULL) {
958 rc = obj->do_ops->do_index_try(env, obj, feat);
963 /* fill ii_flags with supported index features */
964 ii->ii_flags &= (II_FL_NOHASH | II_FL_NOKEY | II_FL_VARKEY |
967 if (!(feat->dif_flags & DT_IND_VARKEY))
968 ii->ii_keysize = feat->dif_keysize_max;
970 if (!(feat->dif_flags & DT_IND_VARREC))
971 ii->ii_recsize = feat->dif_recsize_max;
973 if (feat->dif_flags & DT_IND_NONUNQ)
974 /* key isn't necessarily unique */
975 ii->ii_flags |= II_FL_NONUNQ;
977 if (!fid_is_layout_rbtree(&ii->ii_fid)) {
978 dt_read_lock(env, obj, 0);
979 /* fetch object version before walking the index */
980 ii->ii_version = dt_version_get(env, obj);
983 /* walk the index and fill lu_idxpages with key/record pairs */
984 rc = dt_index_walk(env, obj, rdpg, dt_index_page_build, ii);
985 if (!fid_is_layout_rbtree(&ii->ii_fid))
986 dt_read_unlock(env, obj);
990 LASSERT(ii->ii_count == 0);
991 ii->ii_hash_end = II_END_OFF;
996 dt_object_put(env, obj);
999 EXPORT_SYMBOL(dt_index_read);
1001 #ifdef CONFIG_PROC_FS
1002 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v)
1004 struct dt_device *dt = m->private;
1005 struct obd_statfs osfs;
1007 int rc = dt_statfs(NULL, dt, &osfs);
1009 seq_printf(m, "%u\n", (unsigned) osfs.os_bsize);
1012 EXPORT_SYMBOL(lprocfs_dt_blksize_seq_show);
1014 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v)
1016 struct dt_device *dt = m->private;
1017 struct obd_statfs osfs;
1019 int rc = dt_statfs(NULL, dt, &osfs);
1021 __u32 blk_size = osfs.os_bsize >> 10;
1022 __u64 result = osfs.os_blocks;
1024 while (blk_size >>= 1)
1027 seq_printf(m, "%llu\n", result);
1031 EXPORT_SYMBOL(lprocfs_dt_kbytestotal_seq_show);
1033 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v)
1035 struct dt_device *dt = m->private;
1036 struct obd_statfs osfs;
1038 int rc = dt_statfs(NULL, dt, &osfs);
1040 __u32 blk_size = osfs.os_bsize >> 10;
1041 __u64 result = osfs.os_bfree;
1043 while (blk_size >>= 1)
1046 seq_printf(m, "%llu\n", result);
1050 EXPORT_SYMBOL(lprocfs_dt_kbytesfree_seq_show);
1052 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v)
1054 struct dt_device *dt = m->private;
1055 struct obd_statfs osfs;
1057 int rc = dt_statfs(NULL, dt, &osfs);
1059 __u32 blk_size = osfs.os_bsize >> 10;
1060 __u64 result = osfs.os_bavail;
1062 while (blk_size >>= 1)
1065 seq_printf(m, "%llu\n", result);
1069 EXPORT_SYMBOL(lprocfs_dt_kbytesavail_seq_show);
1071 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v)
1073 struct dt_device *dt = m->private;
1074 struct obd_statfs osfs;
1076 int rc = dt_statfs(NULL, dt, &osfs);
1078 seq_printf(m, "%llu\n", osfs.os_files);
1081 EXPORT_SYMBOL(lprocfs_dt_filestotal_seq_show);
1083 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v)
1085 struct dt_device *dt = m->private;
1086 struct obd_statfs osfs;
1088 int rc = dt_statfs(NULL, dt, &osfs);
1090 seq_printf(m, "%llu\n", osfs.os_ffree);
1093 EXPORT_SYMBOL(lprocfs_dt_filesfree_seq_show);
1095 #endif /* CONFIG_PROC_FS */