1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * linux/fs/obdfilter/filter_san.c
6 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
7 * Author: Peter Braam <braam@clusterfs.com>
8 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * This file is part of Lustre, http://www.lustre.org.
12 * Lustre is free software; you can redistribute it and/or
13 * modify it under the terms of version 2 of the GNU General Public
14 * License as published by the Free Software Foundation.
16 * Lustre is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Lustre; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define DEBUG_SUBSYSTEM S_FILTER
28 #include <linux/config.h>
29 #include <linux/module.h>
30 #include <linux/pagemap.h> // XXX kill me soon
31 #include <linux/version.h>
33 #include <linux/obd_class.h>
34 #include <linux/lustre_fsfilt.h>
35 #include "filter_internal.h"
37 /* sanobd setup methods - use a specific mount option */
38 int filter_san_setup(struct obd_device *obd, obd_count len, void *buf)
40 struct lustre_cfg *lcfg = buf;
44 if (lcfg->lcfg_bufcount < 3 || LUSTRE_CFG_BUFLEN(lcfg, 2) < 1)
47 /* 2.6.9 selinux wants a full option page for do_kern_mount (bug6471) */
48 page = get_zeroed_page(GFP_KERNEL);
52 /* for extN/ext3 filesystem, we must mount it with 'writeback' mode */
53 if (!strcmp(lustre_cfg_string(lcfg, 2), "ldiskfs"))
54 strcpy((void *)page, "data=writeback");
55 else if (!strcmp(lustre_cfg_string(lcfg, 2), "ext3"))
56 strcpy((void *)page, "data=writeback,asyncdel");
58 LBUG(); /* just a reminder */
60 rc = filter_common_setup(obd, len, buf, (void *)page);
66 int filter_san_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
67 int objcount, struct obd_ioobj *obj, int niocount,
68 struct niobuf_remote *nb)
70 struct obd_ioobj *o = obj;
71 struct niobuf_remote *rnb = nb;
75 LASSERT(objcount == 1);
77 for (i = 0; i < objcount; i++, o++) {
78 struct dentry *dentry;
80 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
81 sector_t (*fs_bmap)(struct address_space *, sector_t);
83 int (*fs_bmap)(struct address_space *, long);
87 dentry = filter_oa2dentry(exp->exp_obd, oa);
89 GOTO(out, rc = PTR_ERR(dentry));
91 inode = dentry->d_inode;
93 CERROR("trying to BRW to non-existent file "LPU64"\n",
96 GOTO(out, rc = -ENOENT);
98 fs_bmap = inode->i_mapping->a_ops->bmap;
100 for (j = 0; j < o->ioo_bufcnt; j++, rnb++) {
103 block = rnb->offset >> inode->i_blkbits;
105 if (cmd == OBD_BRW_READ) {
106 block = fs_bmap(inode->i_mapping, block);
108 loff_t newsize = rnb->offset + rnb->len;
109 /* fs_prep_san_write will also update inode
111 * (1) new alloced block
112 * (2) existed block but size extented
114 /* FIXME We could call fs_prep_san_write()
115 * only once for all the blocks allocation.
116 * Now call it once for each block, for
117 * simplicity. And if error happens, we
118 * probably need to release previous alloced
120 rc = fs_prep_san_write(exp->exp_obd, inode,