Whamcloud - gitweb
b=19427 correct lmm_object_id and reserve fids for fid-on-OST.
[fs/lustre-release.git] / lustre / obdclass / linux / linux-obdo.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/obdclass/linux/linux-obdo.c
37  *
38  * Object Devices Class Driver
39  * These are the only exported functions, they provide some generic
40  * infrastructure for managing object devices
41  */
42
43 #define DEBUG_SUBSYSTEM S_CLASS
44 #ifndef EXPORT_SYMTAB
45 # define EXPORT_SYMTAB
46 #endif
47
48 #ifndef __KERNEL__
49 #include <liblustre.h>
50 #else
51 #include <linux/module.h>
52 #include <obd_class.h>
53 #include <lustre/lustre_idl.h>
54 #endif
55
56 #ifdef __KERNEL__
57 #include <linux/fs.h>
58 #include <linux/pagemap.h> /* for PAGE_CACHE_SIZE */
59
60 /*FIXME: Just copy from obdo_from_inode*/
61 void obdo_from_la(struct obdo *dst, struct lu_attr *la, obd_flag valid)
62 {
63         obd_flag newvalid = 0;
64
65         if (valid & OBD_MD_FLATIME) {
66                 dst->o_atime = la->la_atime;
67                 newvalid |= OBD_MD_FLATIME;
68         }
69         if (valid & OBD_MD_FLMTIME) {
70                 dst->o_mtime = la->la_mtime;
71                 newvalid |= OBD_MD_FLMTIME;
72         }
73         if (valid & OBD_MD_FLCTIME) {
74                 dst->o_ctime = la->la_ctime;
75                 newvalid |= OBD_MD_FLCTIME;
76         }
77         if (valid & OBD_MD_FLSIZE) {
78                 dst->o_size = la->la_size;
79                 newvalid |= OBD_MD_FLSIZE;
80         }
81         if (valid & OBD_MD_FLBLOCKS) {  /* allocation of space (x512 bytes) */
82                 dst->o_blocks = la->la_blocks;
83                 newvalid |= OBD_MD_FLBLOCKS;
84         }
85         if (valid & OBD_MD_FLTYPE) {
86                 dst->o_mode = (dst->o_mode & S_IALLUGO)|(la->la_mode & S_IFMT);
87                 newvalid |= OBD_MD_FLTYPE;
88         }
89         if (valid & OBD_MD_FLMODE) {
90                 dst->o_mode = (dst->o_mode & S_IFMT)|(la->la_mode & S_IALLUGO);
91                 newvalid |= OBD_MD_FLMODE;
92         }
93         if (valid & OBD_MD_FLUID) {
94                 dst->o_uid = la->la_uid;
95                 newvalid |= OBD_MD_FLUID;
96         }
97         if (valid & OBD_MD_FLGID) {
98                 dst->o_gid = la->la_gid;
99                 newvalid |= OBD_MD_FLGID;
100         }
101         dst->o_valid |= newvalid;
102 }
103 EXPORT_SYMBOL(obdo_from_la);
104
105 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid)
106 {
107         valid &= src->o_valid;
108
109         if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
110                 CDEBUG(D_INODE,
111                        "valid "LPX64", cur time %lu/%lu, new "LPU64"/"LPU64"\n",
112                        src->o_valid, LTIME_S(dst->i_mtime),
113                        LTIME_S(dst->i_ctime), src->o_mtime, src->o_ctime);
114
115         if (valid & OBD_MD_FLATIME && src->o_atime > LTIME_S(dst->i_atime))
116                 LTIME_S(dst->i_atime) = src->o_atime;
117         if (valid & OBD_MD_FLMTIME && src->o_mtime > LTIME_S(dst->i_mtime))
118                 LTIME_S(dst->i_mtime) = src->o_mtime;
119         if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(dst->i_ctime))
120                 LTIME_S(dst->i_ctime) = src->o_ctime;
121         if (valid & OBD_MD_FLSIZE)
122                 i_size_write(dst, src->o_size);
123         /* optimum IO size */
124         if (valid & OBD_MD_FLBLKSZ && src->o_blksize > (1 << dst->i_blkbits)) {
125                 dst->i_blkbits = cfs_ffs(src->o_blksize) - 1;
126 #ifdef HAVE_INODE_BLKSIZE
127                 dst->i_blksize = src->o_blksize;
128 #endif
129         }
130
131         if (dst->i_blkbits < CFS_PAGE_SHIFT) {
132 #ifdef HAVE_INODE_BLKSIZE
133                 dst->i_blksize = CFS_PAGE_SIZE;
134 #endif
135                 dst->i_blkbits = CFS_PAGE_SHIFT;
136         }
137
138         /* allocation of space */
139         if (valid & OBD_MD_FLBLOCKS && src->o_blocks > dst->i_blocks)
140                 /*
141                  * XXX shouldn't overflow be checked here like in
142                  * obdo_to_inode().
143                  */
144                 dst->i_blocks = src->o_blocks;
145 }
146 EXPORT_SYMBOL(obdo_refresh_inode);
147
148 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
149 {
150         valid &= src->o_valid;
151
152         LASSERTF(!(valid & (OBD_MD_FLTYPE | OBD_MD_FLGENER | OBD_MD_FLFID |
153                             OBD_MD_FLID | OBD_MD_FLGROUP)),
154                  "object "LPU64"/"LPU64", valid %x\n",
155                  src->o_id, src->o_seq, valid);
156
157         if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
158                 CDEBUG(D_INODE,
159                        "valid "LPX64", cur time %lu/%lu, new "LPU64"/"LPU64"\n",
160                        src->o_valid, LTIME_S(dst->i_mtime),
161                        LTIME_S(dst->i_ctime), src->o_mtime, src->o_ctime);
162
163         if (valid & OBD_MD_FLATIME)
164                 LTIME_S(dst->i_atime) = src->o_atime;
165         if (valid & OBD_MD_FLMTIME)
166                 LTIME_S(dst->i_mtime) = src->o_mtime;
167         if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(dst->i_ctime))
168                 LTIME_S(dst->i_ctime) = src->o_ctime;
169         if (valid & OBD_MD_FLSIZE)
170                 i_size_write(dst, src->o_size);
171         if (valid & OBD_MD_FLBLOCKS) { /* allocation of space */
172                 dst->i_blocks = src->o_blocks;
173                 if (dst->i_blocks < src->o_blocks) /* overflow */
174                         dst->i_blocks = -1;
175
176         }
177         if (valid & OBD_MD_FLBLKSZ) {
178                 dst->i_blkbits = cfs_ffs(src->o_blksize)-1;
179 #ifdef HAVE_INODE_BLKSIZE
180                 dst->i_blksize = src->o_blksize;
181 #endif
182         }
183         if (valid & OBD_MD_FLMODE)
184                 dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
185         if (valid & OBD_MD_FLUID)
186                 dst->i_uid = src->o_uid;
187         if (valid & OBD_MD_FLGID)
188                 dst->i_gid = src->o_gid;
189         if (valid & OBD_MD_FLFLAGS)
190                 dst->i_flags = src->o_flags;
191 }
192 EXPORT_SYMBOL(obdo_to_inode);
193 #endif