1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
7 * Copyright (c) 2006 Cluster File Systems, Inc.
8 * Author: Nikita Danilov <nikita@clusterfs.com>
10 * This file is part of the Lustre file system, http://www.lustre.org
11 * Lustre is a trademark of Cluster File Systems, Inc.
13 * You may have signed or agreed to another license before downloading
14 * this software. If so, you are bound by the terms and conditions
15 * of that agreement, and the following does not apply to you. See the
16 * LICENSE file included with this distribution for more information.
18 * If you did not agree to a different license, then this copy of Lustre
19 * is open source software; you can redistribute it and/or modify it
20 * under the terms of version 2 of the GNU General Public License as
21 * published by the Free Software Foundation.
23 * In either case, Lustre is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * license text for more details.
29 * oi uses two mechanisms to implement fid->cookie mapping:
31 * - persistent index, where cookie is a record and fid is a key, and
33 * - algorithmic mapping for "igif" fids.
38 # define EXPORT_SYMTAB
40 #define DEBUG_SUBSYSTEM S_MDS
42 #include <linux/module.h>
44 /* LUSTRE_VERSION_CODE */
45 #include <lustre_ver.h>
47 * struct OBD_{ALLOC,FREE}*()
51 #include <obd_support.h>
54 #include <lustre_fid.h>
57 /* osd_lookup(), struct osd_thread_info */
58 #include "osd_internal.h"
60 #include "dt_object.h"
67 static const struct oi_descr oi_descr[OSD_OI_FID_NR] = {
68 [OSD_OI_FID_SMALL] = {
72 [OSD_OI_FID_OTHER] = {
73 .fid_size = sizeof(struct lu_fid),
78 int osd_oi_init(struct osd_thread_info *info,
79 struct osd_oi *oi, struct dt_device *dev)
83 const struct lu_env *env;
85 CLASSERT(ARRAY_SIZE(oi->oi_dir) == ARRAY_SIZE(oi_descr));
89 memset(oi, 0, sizeof *oi);
91 for (i = rc = 0; i < ARRAY_SIZE(oi->oi_dir) && rc == 0; ++i) {
94 * Allocate on stack---this is initialization.
96 const struct dt_index_features feat = {
97 .dif_flags = DT_IND_UPDATE,
98 .dif_keysize_min = oi_descr[i].fid_size,
99 .dif_keysize_max = oi_descr[i].fid_size,
100 .dif_recsize_min = sizeof(struct osd_inode_id),
101 .dif_recsize_max = sizeof(struct osd_inode_id)
103 struct dt_object *obj;
105 name = oi_descr[i].name;
106 obj = dt_store_open(env, dev, name, &info->oti_fid);
108 rc = obj->do_ops->do_index_try(env, obj, &feat);
110 LASSERT(obj->do_index_ops != NULL);
113 CERROR("Wrong index \"%s\": %d\n", name, rc);
114 lu_object_put(env, &obj->do_lu);
118 CERROR("Cannot open \"%s\": %d\n", name, rc);
122 osd_oi_fini(info, oi);
126 void osd_oi_fini(struct osd_thread_info *info, struct osd_oi *oi)
129 for (i = 0; i < ARRAY_SIZE(oi->oi_dir); ++i) {
130 if (oi->oi_dir[i] != NULL) {
131 lu_object_put(info->oti_env, &oi->oi_dir[i]->do_lu);
132 oi->oi_dir[i] = NULL;
137 static const struct dt_key *oi_fid_key(struct osd_thread_info *info,
139 const struct lu_fid *fid,
140 struct dt_object **idx)
143 struct lu_fid_pack *pack;
145 pack = &info->oti_pack;
146 fid_pack(pack, fid, &info->oti_fid);
147 for (i = 0; i < ARRAY_SIZE(oi->oi_dir); ++i) {
148 if (pack->fp_len == oi_descr[i].fid_size + sizeof pack->fp_len){
149 *idx = oi->oi_dir[i];
150 return (const struct dt_key *)&pack->fp_area;
153 CERROR("Unsupported packed fid size: %d ("DFID")\n",
154 pack->fp_len, PFID(fid));
159 int osd_oi_lookup(struct osd_thread_info *info, struct osd_oi *oi,
160 const struct lu_fid *fid, struct osd_inode_id *id)
164 if (fid_is_igif(fid)) {
165 lu_igif_to_id(fid, id);
168 struct dt_object *idx;
169 const struct dt_key *key;
171 key = oi_fid_key(info, oi, fid, &idx);
172 rc = idx->do_index_ops->dio_lookup(info->oti_env, idx,
173 (struct dt_rec *)id, key,
175 id->oii_ino = be32_to_cpu(id->oii_ino);
176 id->oii_gen = be32_to_cpu(id->oii_gen);
181 int osd_oi_insert(struct osd_thread_info *info, struct osd_oi *oi,
182 const struct lu_fid *fid, const struct osd_inode_id *id0,
185 struct dt_object *idx;
186 struct osd_inode_id *id;
187 const struct dt_key *key;
189 if (fid_is_igif(fid))
192 key = oi_fid_key(info, oi, fid, &idx);
194 id->oii_ino = cpu_to_be32(id0->oii_ino);
195 id->oii_gen = cpu_to_be32(id0->oii_gen);
196 return idx->do_index_ops->dio_insert(info->oti_env, idx,
197 (const struct dt_rec *)id,
198 key, th, BYPASS_CAPA);
201 int osd_oi_delete(struct osd_thread_info *info,
202 struct osd_oi *oi, const struct lu_fid *fid,
205 struct dt_object *idx;
206 const struct dt_key *key;
208 if (fid_is_igif(fid))
211 key = oi_fid_key(info, oi, fid, &idx);
212 return idx->do_index_ops->dio_delete(info->oti_env, idx,
213 key, th, BYPASS_CAPA);