1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre filesystem abstraction routines
7 * Copyright (C) 2004 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 # define EXPORT_SYMTAB
29 #define DEBUG_SUBSYSTEM S_SM
31 #include <linux/kmod.h>
32 #include <linux/init.h>
34 #include <linux/slab.h>
35 #include <linux/obd_class.h>
36 #include <linux/obd_support.h>
37 #include <linux/lustre_lib.h>
38 #include <linux/lustre_idl.h>
39 #include <linux/lustre_fsfilt.h>
40 #include <linux/lustre_smfs.h>
41 #include "smfs_internal.h"
43 static int smfs_ost_get_id(obd_id *id, char *data, int size)
45 /*for obdfilter obdid is the name of the filename*/
49 *id = simple_strtoull(data, &endp, 10);
54 /* Group 0 is no longer a legal group, to catch uninitialized IDs */
55 #define FILTER_MIN_GROUPS 3
56 static int smfs_ost_get_group(struct dentry *dentry, struct obdo *oa)
58 struct smfs_super_info *sinfo = S2SMI(dentry->d_inode->i_sb);
59 struct obd_device *obd = class_exp2obd(sinfo->smsi_exp);
60 struct filter_obd *filter = &obd->u.filter;
61 struct dentry *dparent_subdir = dentry->d_parent;
62 struct dentry *dparent_group = dparent_subdir->d_parent;
65 if (dparent_group == NULL || dparent_group == dparent_subdir)
68 for (i = 1; i < filter->fo_group_count; i++) {
69 if (filter->fo_groups[i] == dparent_group) {
71 oa->o_valid |= OBD_MD_FLGROUP;
78 static int ost_rec_create_pack(char *buffer, struct dentry *dentry,
79 struct inode *dir, void *data1, void *data2)
81 struct obdo *oa = NULL;
84 PACK_KML_REC_INIT(buffer, OST_CREATE);
85 oa = (struct obdo*)buffer;
87 struct obdo *create_oa = (struct obdo *)data2;
88 int num = *((int *)data1);
90 memcpy(oa, create_oa, sizeof(*oa));
91 memcpy(oa->o_inline, &num, sizeof(int));
92 oa->o_valid |= OBD_MD_REINT;
94 oa->o_uid = 0; /* must have 0 uid / gid on OST */
96 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FLTYPE |
97 OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID;
99 obdo_from_inode(oa, dentry->d_inode, OBD_MD_FLTYPE|OBD_MD_FLATIME|
100 OBD_MD_FLMTIME| OBD_MD_FLCTIME);
101 rc = smfs_ost_get_id(&oa->o_id, (char*)dentry->d_name.name,
104 CERROR("Can not find id of node %lu\n", dentry->d_inode->i_ino);
105 GOTO(out, rc = -ENOMEM);
107 rc = smfs_ost_get_group(dentry, oa);
109 CERROR("Can not find group node %lu\n", dentry->d_inode->i_ino);
110 GOTO(out, rc = -ENOMEM);
113 rc = sizeof(*oa) + sizeof(int);
118 static int ost_rec_setattr_pack(char *buffer, struct dentry *dentry,
119 struct inode *dir, void *data1, void *data2)
121 struct obdo *oa = NULL;
122 struct iattr *attr = (struct iattr*)data1;
125 PACK_KML_REC_INIT(buffer, OST_SETATTR);
126 oa = (struct obdo*)buffer;
128 obdo_from_iattr(oa, attr, attr->ia_valid);
130 rc = smfs_ost_get_id(&oa->o_id, (char *)dentry->d_name.name,
133 GOTO(out, rc = -ENOMEM);
134 rc = smfs_ost_get_group(dentry, oa);
136 CERROR("Can not find group node %lu\n", dentry->d_inode->i_ino);
137 GOTO(out, rc = -ENOMEM);
140 rc = sizeof(*oa) + sizeof(int);
145 static int ost_rec_write_pack(char *buffer, struct dentry *dentry,
146 struct inode *dir, void *data1, void *data2)
148 struct obdo *oa = NULL;
151 PACK_KML_REC_INIT(buffer, OST_WRITE);
152 oa = (struct obdo*)buffer;
154 rc = smfs_ost_get_id(&oa->o_id, (char*)dentry->d_name.name,
157 GOTO(out, rc = -ENOMEM);
158 memcpy(oa->o_inline, &dentry->d_inode->i_ino, sizeof(unsigned long));
160 rc = smfs_ost_get_group(dentry, oa);
162 CERROR("Can not find group node %lu\n", dentry->d_inode->i_ino);
163 GOTO(out, rc = -ENOMEM);
165 rc = sizeof(*oa) + sizeof(int);
169 typedef int (*ost_pack_rec_func)(char *buffer, struct dentry *dentry,
170 struct inode *dir, void *data1, void *data2);
171 static ost_pack_rec_func ost_kml_pack[REINT_MAX + 1] = {
172 [REINT_SETATTR] ost_rec_setattr_pack,
173 [REINT_CREATE] ost_rec_create_pack,
174 [REINT_WRITE] ost_rec_write_pack,
177 int ost_rec_pack(char *buffer, struct dentry *dentry, struct inode *dir,
178 void *data1, void *data2, int op)
180 if (op == REINT_SETATTR || op == REINT_CREATE || op == REINT_WRITE) {
181 return ost_kml_pack[op](buffer, dentry, dir, data1, data2);
186 int ost_rec_pack_init(struct smfs_super_info *smsi)
189 smsi->smsi_pack_rec[PACK_OST] = ost_rec_pack;