1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre filesystem abstraction routines
6 * Copyright (C) 2004 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_SM
26 #include <linux/kmod.h>
27 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <linux/obd_class.h>
31 #include <linux/obd_support.h>
32 #include <linux/lustre_lib.h>
33 #include <linux/lustre_idl.h>
34 #include <linux/lustre_fsfilt.h>
35 #include <linux/lustre_lite.h>
36 #include <linux/lustre_mds.h>
37 #include <linux/lustre_smfs.h>
38 #include "smfs_internal.h"
40 static int mds_rec_link_pack(char *buffer, struct dentry *dentry,
41 struct inode *dir, void *data1, void *data2)
43 struct dentry *src = (struct dentry *)data1;
44 struct dentry *tgt = (struct dentry *)data2;
45 struct mds_kml_pack_info *mkpi;
46 struct lustre_msg *msg = NULL;
47 struct mdc_op_data *op_data;
51 OBD_ALLOC(op_data, sizeof(*op_data));
55 mdc_prepare_mdc_data(op_data, src->d_inode, dir,
56 tgt->d_name.name, tgt->d_name.len, 0);
58 PACK_KML_REC_INIT(buffer, MDS_REINT);
59 mkpi = (struct mds_kml_pack_info *)buffer;
61 mkpi->mpi_bufcount = 2;
62 mkpi->mpi_size[0] = sizeof(struct mds_rec_link);
63 mkpi->mpi_size[1] = op_data->namelen + 1;
65 /* the mds reint log format is: opcode + mkpi + request */
66 msg = (struct lustre_msg *)(buffer + sizeof(*mkpi));
67 lustre_init_msg(msg, mkpi->mpi_bufcount, mkpi->mpi_size, NULL);
69 tmp = mdc_link_pack(msg, 0, op_data);
70 OBD_FREE(op_data, sizeof(*op_data));
71 mkpi->mpi_total_size = tmp - (void *)msg;
72 rc = mkpi->mpi_total_size + sizeof(*mkpi) + sizeof(int);
76 /* FIXME-WANGDI: did not think about EA situation. */
77 static int mds_rec_setattr_pack(char *buffer, struct dentry *dentry,
78 struct inode *dir, void *data1, void *data2)
80 struct iattr *iattr = (struct iattr *)data1;
81 struct mds_rec_setattr *rec = NULL;
82 struct mds_kml_pack_info *mkpi;
83 struct lustre_msg *msg = NULL;
84 struct mdc_op_data *op_data;
85 int rc = 0, ealen = 0;
89 OBD_ALLOC(op_data, sizeof(*op_data));
92 mdc_prepare_mdc_data(op_data, dir, NULL, NULL, 0, 0);
94 PACK_KML_REC_INIT(buffer, MDS_REINT);
95 mkpi = (struct mds_kml_pack_info*)buffer;
97 mkpi->mpi_bufcount = 1;
98 mkpi->mpi_size[0] = sizeof(struct mds_rec_setattr);
100 mkpi->mpi_bufcount++;
101 mkpi->mpi_size[1] = *(int *)data2;
102 ealen = *(int *)data2;
103 ea = data2 + sizeof(ealen);
106 msg = (struct lustre_msg *)(buffer + sizeof(*mkpi));
107 lustre_init_msg(msg, mkpi->mpi_bufcount, mkpi->mpi_size, NULL);
109 tmp = mdc_setattr_pack(msg, 0, op_data, iattr, ea, ealen, NULL, 0);
110 OBD_FREE(op_data, sizeof(*op_data));
112 /* FIXME-WANGDI: there are maybe some better ways to set the time
114 rec = (struct mds_rec_setattr *)lustre_msg_buf(msg, 0, 0);
115 if (rec->sa_valid & ATTR_CTIME)
116 rec->sa_valid |= ATTR_CTIME_SET;
117 if (rec->sa_valid & ATTR_MTIME)
118 rec->sa_valid |= ATTR_MTIME_SET;
119 if (rec->sa_valid & ATTR_ATIME)
120 rec->sa_valid |= ATTR_ATIME_SET;
122 mkpi->mpi_total_size = tmp - (void *)msg;
123 rc = mkpi->mpi_total_size + sizeof(*mkpi) + sizeof(int);
128 static int mds_rec_create_pack(char *buffer, struct dentry *dentry,
129 struct inode *dir, void *data1,
132 struct mds_kml_pack_info *mkpi;
133 struct lustre_msg *msg = NULL;
134 struct mdc_op_data *op_data;
135 struct mds_rec_create *rec;
136 int rc = 0, tgt_len = 0;
139 OBD_ALLOC(op_data, sizeof(*op_data));
142 mdc_prepare_mdc_data(op_data, dir, dentry->d_inode,
143 dentry->d_name.name, dentry->d_name.len, 0);
145 PACK_KML_REC_INIT(buffer, MDS_REINT);
146 mkpi = (struct mds_kml_pack_info *)buffer;
148 mkpi->mpi_bufcount = 2;
149 mkpi->mpi_size[0] = sizeof(struct mds_rec_create);
150 mkpi->mpi_size[1] = op_data->namelen + 1;
152 if (data1 && data2) {
153 mkpi->mpi_size[2] = *(int *)data2;
154 mkpi->mpi_bufcount++;
158 /* for symlink, data1 will be the tgt name. */
159 tgt_len = *(int *)data2;
161 msg = (struct lustre_msg *)(buffer + sizeof(*mkpi));
162 lustre_init_msg(msg, mkpi->mpi_bufcount, mkpi->mpi_size, NULL);
164 tmp = mdc_create_pack(msg, 0, op_data, dentry->d_inode->i_mode,
165 dentry->d_inode->i_mode, data1, tgt_len);
167 rec = (struct mds_rec_create *)lustre_msg_buf(msg, 0, 0);
168 rec->cr_replayid = op_data->id2;
169 rec->cr_flags |= REC_REINT_CREATE;
170 mkpi->mpi_total_size = tmp - (void *)msg;
171 rc = mkpi->mpi_total_size + sizeof(*mkpi) + sizeof(int);
172 OBD_FREE(op_data, sizeof(*op_data));
177 static int mds_rec_unlink_pack(char *buffer, struct dentry *dentry,
178 struct inode *dir, void *data1,
181 struct lustre_msg *msg = NULL;
182 struct mds_kml_pack_info *mkpi;
183 struct mdc_op_data *op_data;
184 int mode = *(int*)data1;
188 OBD_ALLOC(op_data, sizeof(*op_data));
191 mdc_prepare_mdc_data(op_data, dir, NULL,
193 dentry->d_name.len, mode);
195 PACK_KML_REC_INIT(buffer, MDS_REINT);
196 mkpi = (struct mds_kml_pack_info*)buffer;
198 mkpi->mpi_bufcount = 2;
199 mkpi->mpi_size[0] = sizeof(struct mds_rec_unlink);
200 mkpi->mpi_size[1] = op_data->namelen + 1;
202 msg = (struct lustre_msg *)(buffer + sizeof(*mkpi));
203 lustre_init_msg(msg, mkpi->mpi_bufcount, mkpi->mpi_size, NULL);
205 tmp = mdc_unlink_pack(msg, 0, op_data);
207 mkpi->mpi_total_size = tmp - (void*)msg;
208 rc = mkpi->mpi_total_size + sizeof(*mkpi) + sizeof(int);
209 OBD_FREE(op_data, sizeof(*op_data));
214 static int mds_rec_rename_pack(char *buffer, struct dentry *dentry,
215 struct inode *dir, void *data1, void *data2)
217 struct dentry *new_dentry = (struct dentry *)data2;
218 struct inode *new_dir = (struct inode *)data1;
219 struct mds_kml_pack_info *mkpi;
220 struct lustre_msg *msg = NULL;
221 struct mdc_op_data *op_data;
222 struct mds_rec_rename *rec;
226 OBD_ALLOC(op_data, sizeof(*op_data));
229 mdc_prepare_mdc_data(op_data, dir, new_dir, NULL, 0, 0);
231 PACK_KML_REC_INIT(buffer, MDS_REINT);
232 mkpi = (struct mds_kml_pack_info*)buffer;
234 mkpi->mpi_bufcount = 3;
235 mkpi->mpi_size[0] = sizeof(struct mds_rec_rename);
236 mkpi->mpi_size[1] = dentry->d_name.len + 1;
237 mkpi->mpi_size[2] = new_dentry->d_name.len + 1;
239 rec = (struct mds_rec_rename *)(buffer + sizeof(*mkpi));
242 msg = (struct lustre_msg *)(buffer + sizeof(*mkpi));
243 lustre_init_msg(msg, mkpi->mpi_bufcount, mkpi->mpi_size, NULL);
245 tmp = mdc_rename_pack(msg, 0, op_data, dentry->d_name.name,
246 dentry->d_name.len, new_dentry->d_name.name,
247 new_dentry->d_name.len);
249 mkpi->mpi_total_size = tmp - (void*)msg;
250 rc = mkpi->mpi_total_size + sizeof(*mkpi) + sizeof(int);
251 OBD_FREE(op_data, sizeof(*op_data));
255 typedef int (*mds_pack_rec_func)(char *buffer, struct dentry *dentry,
256 struct inode *dir, void *data1, void *data2);
258 static mds_pack_rec_func mds_kml_pack[REINT_MAX + 1] = {
259 [REINT_LINK] mds_rec_link_pack,
260 [REINT_SETATTR] mds_rec_setattr_pack,
261 [REINT_CREATE] mds_rec_create_pack,
262 [REINT_UNLINK] mds_rec_unlink_pack,
263 [REINT_RENAME] mds_rec_rename_pack,
266 int mds_rec_pack(char *buffer, struct dentry *dentry, struct inode *dir,
267 void *data1, void *data2, int op)
269 return mds_kml_pack[op](buffer, dentry, dir, data1, data2);
272 int mds_rec_pack_init(struct smfs_super_info *smsi)
275 smsi->smsi_pack_rec[PACK_MDS] = mds_rec_pack;