1 /* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Copyright (C) 2006 Cluster File Systems, Inc.
7 * Author: WangDi <wangdi@clusterfs.com>
9 * This file is part of the Lustre file system, http://www.lustre.org
10 * Lustre is a trademark of Cluster File Systems, Inc.
12 * You may have signed or agreed to another license before downloading
13 * this software. If so, you are bound by the terms and conditions
14 * of that agreement, and the following does not apply to you. See the
15 * LICENSE file included with this distribution for more information.
17 * If you did not agree to a different license, then this copy of Lustre
18 * is open source software; you can redistribute it and/or modify it
19 * under the terms of version 2 of the GNU General Public License as
20 * published by the Free Software Foundation.
22 * In either case, Lustre is distributed in the hope that it will be
23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * license text for more details.
28 # define EXPORT_SYMTAB
30 #define DEBUG_SUBSYSTEM S_LLITE
32 #include <linux/module.h>
34 #include <linux/obd.h>
35 #include <linux/obd_class.h>
36 #include <linux/lustre_ver.h>
37 #include <linux/obd_support.h>
38 #include <linux/lprocfs_status.h>
39 #include <linux/jbd.h>
41 #include <linux/dt_object.h>
42 #include <linux/md_object.h>
43 #include <linux/lustre_mdc.h>
44 #include <linux/lustre_fid.h>
45 #include <linux/lustre_iam.h>
46 #include "fld_internal.h"
51 struct fld_info fld_info;
53 int fld_handle_insert(struct fld_info *fld_info,
54 fidseq_t seq_num, mdsno_t mdsno)
56 handle_t *handle = NULL;
58 return iam_insert(handle, fld_info->fi_container,
59 (struct iam_key *)&seq_num, (struct iam_rec *)&mdsno);
62 int fld_handle_delete(struct fld_info *fld_info,
63 fidseq_t seq_num, mdsno_t mds_num)
65 handle_t *handle = NULL;
67 return iam_delete(handle, fld_info->fi_container,
68 (struct iam_key *)&seq_num);
71 int fld_handle_lookup(struct fld_info *fld_info,
72 fidseq_t seq_num, mdsno_t *mds_num)
78 result = iam_lookup(fld_info->fi_container, (struct iam_key *)&seq_num,
79 (struct iam_rec *)&mdsno);
88 static __u32 fld_root_ptr(struct iam_container *c)
93 static int fld_node_check(struct iam_path *path, struct iam_frame *frame)
96 struct iam_entry *entries;
97 struct super_block *sb;
99 data = frame->bh->b_data;
100 entries = dx_node_get_entries(path, frame);
101 sb = path_obj(path)->i_sb;
102 if (frame == path->ip_frames) {
103 struct iam_cookie *ic = path->ip_descr_data;
105 path->ip_key_target = ic->ic_key;
108 assert(entries == data + path_descr(path)->id_node_gap);
109 assert(dx_get_limit(entries) == dx_node_limit(path));
111 frame->entries = frame->at = entries;
115 static int fld_node_init(struct iam_container *c, struct buffer_head *bh,
121 static int fld_keycmp(struct iam_container *c,
122 struct iam_key *k1, struct iam_key *k2)
124 return key_cmp(le64_to_cpu(*(__u64 *)k1), le64_to_cpu(*(__u64 *)k2));
127 static int fld_node_read(struct iam_container *c, iam_ptr_t ptr,
128 handle_t *h, struct buffer_head **bh)
132 *bh = ext3_bread(h, c->ic_object, (int)ptr, 0, &result);
139 struct iam_descr fld_param = {
140 .id_key_size = sizeof ((struct lu_fid *)0)->f_seq,
141 .id_ptr_size = 4, /* 32 bit block numbers for now */
142 .id_rec_size = sizeof(mdsno_t),
143 .id_node_gap = 0, /* no gaps in index nodes */
146 .id_root_ptr = fld_root_ptr, /* returns 0: root is always at the
147 * beginning of the file (as it
149 .id_node_read = fld_node_read,
150 .id_node_check = fld_node_check,
151 .id_node_init = fld_node_init,
152 .id_keycmp = fld_keycmp,
155 int fld_info_init(struct fld_info *fld_info)
157 struct file *fld_file;
161 fld_file = filp_open("/dev/null", O_RDWR, S_IRWXU);
162 /* sanity and security checks... */
163 OBD_ALLOC(fld_info->fi_container, sizeof(struct iam_container));
164 if (!fld_info->fi_container)
167 rc = iam_container_init(fld_info->fi_container, &fld_param,
168 fld_file->f_dentry->d_inode);
172 void fld_info_fini(struct fld_info *fld_info)
174 iam_container_fini(fld_info->fi_container);
175 OBD_FREE(fld_info->fi_container, sizeof(struct iam_container));
176 OBD_FREE_PTR(fld_info);