4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lustre/obdclass/linux/linux-obdo.c
36 * Object Devices Class Driver
37 * These are the only exported functions, they provide some generic
38 * infrastructure for managing object devices
41 #define DEBUG_SUBSYSTEM S_CLASS
44 #include <liblustre.h>
46 #include <linux/module.h>
47 #include <obd_class.h>
48 #include <lustre/lustre_idl.h>
53 #include <linux/pagemap.h> /* for PAGE_CACHE_SIZE */
55 /*FIXME: Just copy from obdo_from_inode*/
56 void obdo_from_la(struct obdo *dst, struct lu_attr *la, __u64 valid)
58 obd_flag newvalid = 0;
60 if (valid & LA_ATIME) {
61 dst->o_atime = la->la_atime;
62 newvalid |= OBD_MD_FLATIME;
64 if (valid & LA_MTIME) {
65 dst->o_mtime = la->la_mtime;
66 newvalid |= OBD_MD_FLMTIME;
68 if (valid & LA_CTIME) {
69 dst->o_ctime = la->la_ctime;
70 newvalid |= OBD_MD_FLCTIME;
72 if (valid & LA_SIZE) {
73 dst->o_size = la->la_size;
74 newvalid |= OBD_MD_FLSIZE;
76 if (valid & LA_BLOCKS) { /* allocation of space (x512 bytes) */
77 dst->o_blocks = la->la_blocks;
78 newvalid |= OBD_MD_FLBLOCKS;
80 if (valid & LA_TYPE) {
81 dst->o_mode = (dst->o_mode & S_IALLUGO) |
82 (la->la_mode & S_IFMT);
83 newvalid |= OBD_MD_FLTYPE;
85 if (valid & LA_MODE) {
86 dst->o_mode = (dst->o_mode & S_IFMT) |
87 (la->la_mode & S_IALLUGO);
88 newvalid |= OBD_MD_FLMODE;
91 dst->o_uid = la->la_uid;
92 newvalid |= OBD_MD_FLUID;
95 dst->o_gid = la->la_gid;
96 newvalid |= OBD_MD_FLGID;
98 dst->o_valid |= newvalid;
100 EXPORT_SYMBOL(obdo_from_la);
102 /*FIXME: Just copy from obdo_from_inode*/
103 void la_from_obdo(struct lu_attr *dst, struct obdo *obdo, obd_flag valid)
107 valid &= obdo->o_valid;
109 if (valid & OBD_MD_FLATIME) {
110 dst->la_atime = obdo->o_atime;
111 newvalid |= LA_ATIME;
113 if (valid & OBD_MD_FLMTIME) {
114 dst->la_mtime = obdo->o_mtime;
115 newvalid |= LA_MTIME;
117 if (valid & OBD_MD_FLCTIME) {
118 dst->la_ctime = obdo->o_ctime;
119 newvalid |= LA_CTIME;
121 if (valid & OBD_MD_FLSIZE) {
122 dst->la_size = obdo->o_size;
125 if (valid & OBD_MD_FLBLOCKS) {
126 dst->la_blocks = obdo->o_blocks;
127 newvalid |= LA_BLOCKS;
129 if (valid & OBD_MD_FLTYPE) {
130 dst->la_mode = (dst->la_mode & S_IALLUGO) |
131 (obdo->o_mode & S_IFMT);
134 if (valid & OBD_MD_FLMODE) {
135 dst->la_mode = (dst->la_mode & S_IFMT) |
136 (obdo->o_mode & S_IALLUGO);
139 if (valid & OBD_MD_FLUID) {
140 dst->la_uid = obdo->o_uid;
143 if (valid & OBD_MD_FLGID) {
144 dst->la_gid = obdo->o_gid;
147 dst->la_valid = newvalid;
149 EXPORT_SYMBOL(la_from_obdo);
151 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid)
153 valid &= src->o_valid;
155 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
157 "valid "LPX64", cur time %lu/%lu, new "LPU64"/"LPU64"\n",
158 src->o_valid, LTIME_S(dst->i_mtime),
159 LTIME_S(dst->i_ctime), src->o_mtime, src->o_ctime);
161 if (valid & OBD_MD_FLATIME && src->o_atime > LTIME_S(dst->i_atime))
162 LTIME_S(dst->i_atime) = src->o_atime;
163 if (valid & OBD_MD_FLMTIME && src->o_mtime > LTIME_S(dst->i_mtime))
164 LTIME_S(dst->i_mtime) = src->o_mtime;
165 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(dst->i_ctime))
166 LTIME_S(dst->i_ctime) = src->o_ctime;
167 if (valid & OBD_MD_FLSIZE)
168 i_size_write(dst, src->o_size);
169 /* optimum IO size */
170 if (valid & OBD_MD_FLBLKSZ && src->o_blksize > (1 << dst->i_blkbits))
171 dst->i_blkbits = ffs(src->o_blksize) - 1;
173 if (dst->i_blkbits < CFS_PAGE_SHIFT)
174 dst->i_blkbits = CFS_PAGE_SHIFT;
176 /* allocation of space */
177 if (valid & OBD_MD_FLBLOCKS && src->o_blocks > dst->i_blocks)
179 * XXX shouldn't overflow be checked here like in
182 dst->i_blocks = src->o_blocks;
184 EXPORT_SYMBOL(obdo_refresh_inode);
186 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
188 valid &= src->o_valid;
190 LASSERTF(!(valid & (OBD_MD_FLTYPE | OBD_MD_FLGENER | OBD_MD_FLFID |
191 OBD_MD_FLID | OBD_MD_FLGROUP)),
192 "object "LPU64"/"LPU64", valid %x\n",
193 src->o_id, src->o_seq, valid);
195 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
197 "valid "LPX64", cur time %lu/%lu, new "LPU64"/"LPU64"\n",
198 src->o_valid, LTIME_S(dst->i_mtime),
199 LTIME_S(dst->i_ctime), src->o_mtime, src->o_ctime);
201 if (valid & OBD_MD_FLATIME)
202 LTIME_S(dst->i_atime) = src->o_atime;
203 if (valid & OBD_MD_FLMTIME)
204 LTIME_S(dst->i_mtime) = src->o_mtime;
205 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(dst->i_ctime))
206 LTIME_S(dst->i_ctime) = src->o_ctime;
207 if (valid & OBD_MD_FLSIZE)
208 i_size_write(dst, src->o_size);
209 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space */
210 dst->i_blocks = src->o_blocks;
211 if (dst->i_blocks < src->o_blocks) /* overflow */
215 if (valid & OBD_MD_FLBLKSZ)
216 dst->i_blkbits = ffs(src->o_blksize)-1;
217 if (valid & OBD_MD_FLMODE)
218 dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
219 if (valid & OBD_MD_FLUID)
220 dst->i_uid = src->o_uid;
221 if (valid & OBD_MD_FLGID)
222 dst->i_gid = src->o_gid;
223 if (valid & OBD_MD_FLFLAGS)
224 dst->i_flags = src->o_flags;
226 EXPORT_SYMBOL(obdo_to_inode);