Whamcloud - gitweb
- allocation of new fids before sending open or create RPC, using allocated fid in...
[fs/lustre-release.git] / lustre / llite / rw24.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre Lite I/O page cache for the 2.4 kernel version
5  *
6  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
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.
13  *
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.
18  *
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.
22  */
23
24 #include <linux/config.h>
25 #include <linux/kernel.h>
26 #include <linux/mm.h>
27 #include <linux/string.h>
28 #include <linux/stat.h>
29 #include <linux/errno.h>
30 #include <linux/smp_lock.h>
31 #include <linux/unistd.h>
32 #include <linux/version.h>
33 #include <asm/system.h>
34 #include <asm/uaccess.h>
35
36 #include <linux/fs.h>
37 #include <linux/iobuf.h>
38 #include <linux/stat.h>
39 #include <asm/uaccess.h>
40 #include <asm/segment.h>
41 #include <linux/mm.h>
42 #include <linux/pagemap.h>
43 #include <linux/smp_lock.h>
44
45 #define DEBUG_SUBSYSTEM S_LLITE
46
47 #include <linux/lustre_mdc.h>
48 #include <linux/lustre_lite.h>
49 #include "llite_internal.h"
50 #include <linux/lustre_compat25.h>
51
52 static int ll_direct_IO_24(int rw,
53 #ifdef HAVE_DIO_FILE
54                            struct file *file,
55 #else
56                            struct inode *inode,
57 #endif
58                            struct kiobuf *iobuf, unsigned long blocknr,
59                            int blocksize)
60 {
61 #ifdef HAVE_DIO_FILE
62         struct inode *inode = file->f_dentry->d_inode;
63 #endif
64         struct ll_inode_info *lli = ll_i2info(inode);
65         struct lov_stripe_md *lsm = lli->lli_smd;
66         struct brw_page *pga;
67         struct ptlrpc_request_set *set;
68         struct obdo oa;
69         int length, i, flags, rc = 0;
70         loff_t offset;
71         ENTRY;
72
73         if (!lsm || !lsm->lsm_object_id)
74                 RETURN(-EBADF);
75
76         /* FIXME: io smaller than PAGE_SIZE is broken on ia64 */
77         if ((iobuf->offset & (PAGE_SIZE - 1)) ||
78             (iobuf->length & (PAGE_SIZE - 1)))
79                 RETURN(-EINVAL);
80
81         set = ptlrpc_prep_set();
82         if (set == NULL)
83                 RETURN(-ENOMEM);
84
85         OBD_ALLOC(pga, sizeof(*pga) * iobuf->nr_pages);
86         if (!pga) {
87                 ptlrpc_set_destroy(set);
88                 RETURN(-ENOMEM);
89         }
90
91         flags = 0 /* | OBD_BRW_DIRECTIO */;
92         offset = ((obd_off)blocknr << inode->i_blkbits);
93         length = iobuf->length;
94         rw = rw ? OBD_BRW_WRITE : OBD_BRW_READ;
95
96         for (i = 0, length = iobuf->length; length > 0;
97              length -= pga[i].count, offset += pga[i].count, i++) { /*i last!*/
98                 pga[i].pg = iobuf->maplist[i];
99                 pga[i].off = offset;
100                 /* To the end of the page, or the length, whatever is less */
101                 pga[i].count = min_t(int, PAGE_SIZE - (offset & ~PAGE_MASK),
102                                      length);
103                 pga[i].flag = flags;
104                 if (rw == OBD_BRW_READ)
105                         POISON_PAGE(iobuf->maplist[i], 0x0d);
106         }
107
108         ll_inode_fill_obdo(inode, rw, &oa);
109
110         if (rw == OBD_BRW_WRITE)
111                 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
112                                     LPROC_LL_DIRECT_WRITE, iobuf->length);
113         else
114                 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
115                                     LPROC_LL_DIRECT_READ, iobuf->length);
116         rc = obd_brw_async(rw, ll_i2obdexp(inode), &oa, lsm, iobuf->nr_pages,
117                            pga, set, NULL);
118         if (rc) {
119                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
120                        "error from obd_brw_async: rc = %d\n", rc);
121         } else {
122                 rc = ptlrpc_set_wait(set);
123                 if (rc)
124                         CERROR("error from callback: rc = %d\n", rc);
125         }
126         ptlrpc_set_destroy(set);
127         if (rc == 0) {
128                 rc = iobuf->length;
129                 if (rw == OBD_BRW_WRITE) {
130                         lov_stripe_lock(lsm);
131                         obd_adjust_kms(ll_i2obdexp(inode), lsm, offset, 0);
132                         lov_stripe_unlock(lsm);
133                 }
134         }
135
136         OBD_FREE(pga, sizeof(*pga) * iobuf->nr_pages);
137         RETURN(rc);
138 }
139
140 #ifdef KERNEL_HAS_AS_MAX_READAHEAD
141 static int ll_max_readahead(struct inode *inode)
142 {
143         return 0;
144 }
145 #endif
146
147 struct address_space_operations ll_aops = {
148         .readpage       = ll_readpage,
149         .direct_IO      = ll_direct_IO_24,
150         .writepage      = ll_writepage,
151         .prepare_write  = ll_prepare_write,
152         .commit_write   = ll_commit_write,
153         .removepage     = ll_removepage,
154         .sync_page      = NULL,
155         .bmap           = NULL,
156 #ifdef KERNEL_HAS_AS_MAX_READAHEAD
157         .max_readahead  = ll_max_readahead,
158 #endif
159 };