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;
43 if (!lcfg->lcfg_inlbuf2)
46 /* for extN/ext3 filesystem, we must mount it with 'writeback' mode */
47 if (!strcmp(lcfg->lcfg_inlbuf2, "extN"))
48 option = "data=writeback";
49 else if (!strcmp(lcfg->lcfg_inlbuf2, "ext3"))
50 option = "data=writeback,asyncdel";
52 LBUG(); /* just a reminder */
54 return filter_common_setup(obd, len, buf, option);
57 int filter_san_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
58 int objcount, struct obd_ioobj *obj, int niocount,
59 struct niobuf_remote *nb)
61 struct obd_ioobj *o = obj;
62 struct niobuf_remote *rnb = nb;
66 LASSERT(objcount == 1);
68 for (i = 0; i < objcount; i++, o++) {
69 struct dentry *dentry;
71 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
72 sector_t (*fs_bmap)(struct address_space *, sector_t);
74 int (*fs_bmap)(struct address_space *, long);
78 dentry = filter_oa2dentry(exp->exp_obd, oa);
80 GOTO(out, rc = PTR_ERR(dentry));
82 inode = dentry->d_inode;
84 CERROR("trying to BRW to non-existent file "LPU64"\n",
87 GOTO(out, rc = -ENOENT);
89 fs_bmap = inode->i_mapping->a_ops->bmap;
91 for (j = 0; j < o->ioo_bufcnt; j++, rnb++) {
94 block = rnb->offset >> inode->i_blkbits;
96 if (cmd == OBD_BRW_READ) {
97 block = fs_bmap(inode->i_mapping, block);
99 loff_t newsize = rnb->offset + rnb->len;
100 /* fs_prep_san_write will also update inode
102 * (1) new alloced block
103 * (2) existed block but size extented
105 /* FIXME We could call fs_prep_san_write()
106 * only once for all the blocks allocation.
107 * Now call it once for each block, for
108 * simplicity. And if error happens, we
109 * probably need to release previous alloced
111 rc = fs_prep_san_write(exp->exp_obd, inode,