1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/obdo.c
38 * Object Devices Class Driver
39 * These are the only exported functions, they provide some generic
40 * infrastructure for managing object devices
43 #define DEBUG_SUBSYSTEM S_CLASS
45 # define EXPORT_SYMTAB
49 #include <liblustre.h>
52 #include <obd_class.h>
53 #include <lustre/lustre_idl.h>
56 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid)
59 CDEBUG(D_INODE, "src obdo "LPX64" valid "LPX64", dst obdo "LPX64"\n",
60 src->o_id, src->o_valid, dst->o_id);
62 if (valid & OBD_MD_FLATIME)
63 dst->o_atime = src->o_atime;
64 if (valid & OBD_MD_FLMTIME)
65 dst->o_mtime = src->o_mtime;
66 if (valid & OBD_MD_FLCTIME)
67 dst->o_ctime = src->o_ctime;
68 if (valid & OBD_MD_FLSIZE)
69 dst->o_size = src->o_size;
70 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
71 dst->o_blocks = src->o_blocks;
72 if (valid & OBD_MD_FLBLKSZ)
73 dst->o_blksize = src->o_blksize;
74 if (valid & OBD_MD_FLTYPE)
75 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
76 if (valid & OBD_MD_FLMODE)
77 dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
78 if (valid & OBD_MD_FLUID)
79 dst->o_uid = src->o_uid;
80 if (valid & OBD_MD_FLGID)
81 dst->o_gid = src->o_gid;
82 if (valid & OBD_MD_FLFLAGS)
83 dst->o_flags = src->o_flags;
84 if (valid & OBD_MD_FLGENER)
85 dst->o_generation = src->o_generation;
86 if (valid & OBD_MD_FLHANDLE)
87 dst->o_handle = src->o_handle;
88 if (valid & OBD_MD_FLCOOKIE)
89 dst->o_lcookie = src->o_lcookie;
91 dst->o_valid |= valid;
93 EXPORT_SYMBOL(obdo_cpy_md);
95 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
96 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare)
100 if ( compare & OBD_MD_FLATIME )
101 res = (res || (dst->o_atime != src->o_atime));
102 if ( compare & OBD_MD_FLMTIME )
103 res = (res || (dst->o_mtime != src->o_mtime));
104 if ( compare & OBD_MD_FLCTIME )
105 res = (res || (dst->o_ctime != src->o_ctime));
106 if ( compare & OBD_MD_FLSIZE )
107 res = (res || (dst->o_size != src->o_size));
108 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
109 res = (res || (dst->o_blocks != src->o_blocks));
110 if ( compare & OBD_MD_FLBLKSZ )
111 res = (res || (dst->o_blksize != src->o_blksize));
112 if ( compare & OBD_MD_FLTYPE )
113 res = (res || (((dst->o_mode ^ src->o_mode) & S_IFMT) != 0));
114 if ( compare & OBD_MD_FLMODE )
115 res = (res || (((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0));
116 if ( compare & OBD_MD_FLUID )
117 res = (res || (dst->o_uid != src->o_uid));
118 if ( compare & OBD_MD_FLGID )
119 res = (res || (dst->o_gid != src->o_gid));
120 if ( compare & OBD_MD_FLFLAGS )
121 res = (res || (dst->o_flags != src->o_flags));
122 if ( compare & OBD_MD_FLNLINK )
123 res = (res || (dst->o_nlink != src->o_nlink));
124 if ( compare & OBD_MD_FLGENER )
125 res = (res || (dst->o_generation != src->o_generation));
126 /* XXX Don't know if thses should be included here - wasn't previously
127 if ( compare & OBD_MD_FLINLINE )
128 res = (res || memcmp(dst->o_inline, src->o_inline));
132 EXPORT_SYMBOL(obdo_cmp_md);
134 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj)
136 ioobj->ioo_id = oa->o_id;
137 if (oa->o_valid & OBD_MD_FLGROUP)
138 ioobj->ioo_gr = oa->o_gr;
141 ioobj->ioo_type = oa->o_mode;
143 EXPORT_SYMBOL(obdo_to_ioobj);
145 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned int ia_valid)
147 if (ia_valid & ATTR_ATIME) {
148 oa->o_atime = LTIME_S(attr->ia_atime);
149 oa->o_valid |= OBD_MD_FLATIME;
151 if (ia_valid & ATTR_MTIME) {
152 oa->o_mtime = LTIME_S(attr->ia_mtime);
153 oa->o_valid |= OBD_MD_FLMTIME;
155 if (ia_valid & ATTR_CTIME) {
156 oa->o_ctime = LTIME_S(attr->ia_ctime);
157 oa->o_valid |= OBD_MD_FLCTIME;
159 if (ia_valid & ATTR_SIZE) {
160 oa->o_size = attr->ia_size;
161 oa->o_valid |= OBD_MD_FLSIZE;
163 if (ia_valid & ATTR_MODE) {
164 oa->o_mode = attr->ia_mode;
165 oa->o_valid |= OBD_MD_FLTYPE | OBD_MD_FLMODE;
166 if (!in_group_p(oa->o_gid) && !cfs_capable(CFS_CAP_FSETID))
167 oa->o_mode &= ~S_ISGID;
169 if (ia_valid & ATTR_UID) {
170 oa->o_uid = attr->ia_uid;
171 oa->o_valid |= OBD_MD_FLUID;
173 if (ia_valid & ATTR_GID) {
174 oa->o_gid = attr->ia_gid;
175 oa->o_valid |= OBD_MD_FLGID;
178 EXPORT_SYMBOL(obdo_from_iattr);
180 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid)
182 valid &= oa->o_valid;
184 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
185 CDEBUG(D_INODE, "valid "LPX64", new time "LPU64"/"LPU64"\n",
186 oa->o_valid, oa->o_mtime, oa->o_ctime);
189 if (valid & OBD_MD_FLATIME) {
190 LTIME_S(attr->ia_atime) = oa->o_atime;
191 attr->ia_valid |= ATTR_ATIME;
193 if (valid & OBD_MD_FLMTIME) {
194 LTIME_S(attr->ia_mtime) = oa->o_mtime;
195 attr->ia_valid |= ATTR_MTIME;
197 if (valid & OBD_MD_FLCTIME) {
198 LTIME_S(attr->ia_ctime) = oa->o_ctime;
199 attr->ia_valid |= ATTR_CTIME;
201 if (valid & OBD_MD_FLSIZE) {
202 attr->ia_size = oa->o_size;
203 attr->ia_valid |= ATTR_SIZE;
205 #if 0 /* you shouldn't be able to change a file's type with setattr */
206 if (valid & OBD_MD_FLTYPE) {
207 attr->ia_mode = (attr->ia_mode & ~S_IFMT)|(oa->o_mode & S_IFMT);
208 attr->ia_valid |= ATTR_MODE;
211 if (valid & OBD_MD_FLMODE) {
212 attr->ia_mode = (attr->ia_mode & S_IFMT)|(oa->o_mode & ~S_IFMT);
213 attr->ia_valid |= ATTR_MODE;
214 if (!in_group_p(oa->o_gid) && !cfs_capable(CFS_CAP_FSETID))
215 attr->ia_mode &= ~S_ISGID;
217 if (valid & OBD_MD_FLUID) {
218 attr->ia_uid = oa->o_uid;
219 attr->ia_valid |= ATTR_UID;
221 if (valid & OBD_MD_FLGID) {
222 attr->ia_gid = oa->o_gid;
223 attr->ia_valid |= ATTR_GID;
226 EXPORT_SYMBOL(iattr_from_obdo);
228 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid)
230 iattr_from_obdo(&op_data->op_attr, oa, valid);
231 if (valid & OBD_MD_FLBLOCKS) {
232 op_data->op_attr_blocks = oa->o_blocks;
233 op_data->op_attr.ia_valid |= ATTR_BLOCKS;
235 if (valid & OBD_MD_FLFLAGS) {
236 ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags =
238 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
241 EXPORT_SYMBOL(md_from_obdo);
243 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
246 obdo_from_iattr(oa, &op_data->op_attr, valid);
247 if (valid & ATTR_BLOCKS) {
248 oa->o_blocks = op_data->op_attr_blocks;
249 oa->o_valid |= OBD_MD_FLBLOCKS;
251 if (valid & ATTR_ATTR_FLAG) {
253 ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags;
254 oa->o_valid |= OBD_MD_FLFLAGS;
257 EXPORT_SYMBOL(obdo_from_md);