Whamcloud - gitweb
split part of md_operations into md_dir_operations. Cannot test as fld does not work
[fs/lustre-release.git] / lustre / fld / fld_iam.c
1 /* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  fld/fld.c
5  *
6  *  Copyright (C) 2006 Cluster File Systems, Inc.
7  *   Author: WangDi <wangdi@clusterfs.com>
8  *
9  *   This file is part of the Lustre file system, http://www.lustre.org
10  *   Lustre is a trademark of Cluster File Systems, Inc.
11  *
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.
16  *
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.
21  *
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.
26  */
27 #ifndef EXPORT_SYMTAB
28 # define EXPORT_SYMTAB
29 #endif
30 #define DEBUG_SUBSYSTEM S_LLITE
31
32 #include <linux/module.h>
33
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>
40
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"
47
48 struct iam_key;
49 struct iam_rec;
50
51 struct fld_info fld_info;
52
53 int fld_handle_insert(struct fld_info *fld_info,
54                       fidseq_t seq_num, mdsno_t mdsno)
55 {
56         handle_t *handle = NULL;
57         return 0;
58         return iam_insert(handle, fld_info->fi_container,
59                           (struct iam_key *)&seq_num, (struct iam_rec *)&mdsno);
60 }
61
62 int fld_handle_delete(struct fld_info *fld_info,
63                       fidseq_t seq_num, mdsno_t mds_num)
64 {
65         handle_t *handle = NULL;
66         return 0;
67         return iam_delete(handle, fld_info->fi_container,
68                           (struct iam_key *)&seq_num);
69 }
70
71 int fld_handle_lookup(struct fld_info *fld_info,
72                       fidseq_t seq_num, mdsno_t *mds_num)
73 {
74         mdsno_t mdsno;
75         int result;
76
77         return 0;
78         result = iam_lookup(fld_info->fi_container, (struct iam_key *)&seq_num,
79                             (struct iam_rec *)&mdsno);
80         if (result == 0)
81                 return -ENOENT;
82         else if (result > 0)
83                 return mdsno;
84         else
85                 return result;
86 }
87
88 static __u32 fld_root_ptr(struct iam_container *c)
89 {
90         return 0;
91 }
92
93 static int fld_node_check(struct iam_path *path, struct iam_frame *frame)
94 {
95         void *data;
96         struct iam_entry *entries;
97         struct super_block *sb;
98
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;
104                /* root node */
105                 path->ip_key_target = ic->ic_key;
106         } else {
107                 /* non-root index */
108                 assert(entries == data + path_descr(path)->id_node_gap);
109                 assert(dx_get_limit(entries) == dx_node_limit(path));
110         }
111         frame->entries = frame->at = entries;
112         return 0;
113 }
114
115 static int fld_node_init(struct iam_container *c, struct buffer_head *bh,
116                            int root)
117 {
118         return 0;
119 }
120
121 static int fld_keycmp(struct iam_container *c,
122                       struct iam_key *k1, struct iam_key *k2)
123 {
124         return key_cmp(le64_to_cpu(*(__u64 *)k1), le64_to_cpu(*(__u64 *)k2));
125 }
126
127 static int fld_node_read(struct iam_container *c, iam_ptr_t ptr,
128                          handle_t *h, struct buffer_head **bh)
129 {
130         int result = 0;
131 #if 0
132         *bh = ext3_bread(h, c->ic_object, (int)ptr, 0, &result);
133         if (*bh == NULL)
134                 result = -EIO;
135 #endif
136         return result;
137 }
138
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 */
144         .id_root_gap = 0,
145
146         .id_root_ptr   = fld_root_ptr, /* returns 0: root is always at the
147                                         * beginning of the file (as it
148                                         * htree) */
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,
153 };
154
155 int fld_info_init(struct fld_info *fld_info)
156 {
157         struct file *fld_file;
158         int rc;
159         ENTRY;
160
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)
165                 RETURN(-ENOMEM);
166
167         rc = iam_container_init(fld_info->fi_container, &fld_param,
168                                 fld_file->f_dentry->d_inode);
169         RETURN(rc);
170 }
171
172 void fld_info_fini(struct fld_info *fld_info)
173 {
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);
177 }
178