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 (!cfs_curproc_is_in_groups(oa->o_gid) &&
167 !cfs_capable(CFS_CAP_FSETID))
168 oa->o_mode &= ~S_ISGID;
170 if (ia_valid & ATTR_UID) {
171 oa->o_uid = attr->ia_uid;
172 oa->o_valid |= OBD_MD_FLUID;
174 if (ia_valid & ATTR_GID) {
175 oa->o_gid = attr->ia_gid;
176 oa->o_valid |= OBD_MD_FLGID;
179 EXPORT_SYMBOL(obdo_from_iattr);
181 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid)
183 valid &= oa->o_valid;
185 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
186 CDEBUG(D_INODE, "valid "LPX64", new time "LPU64"/"LPU64"\n",
187 oa->o_valid, oa->o_mtime, oa->o_ctime);
190 if (valid & OBD_MD_FLATIME) {
191 LTIME_S(attr->ia_atime) = oa->o_atime;
192 attr->ia_valid |= ATTR_ATIME;
194 if (valid & OBD_MD_FLMTIME) {
195 LTIME_S(attr->ia_mtime) = oa->o_mtime;
196 attr->ia_valid |= ATTR_MTIME;
198 if (valid & OBD_MD_FLCTIME) {
199 LTIME_S(attr->ia_ctime) = oa->o_ctime;
200 attr->ia_valid |= ATTR_CTIME;
202 if (valid & OBD_MD_FLSIZE) {
203 attr->ia_size = oa->o_size;
204 attr->ia_valid |= ATTR_SIZE;
206 #if 0 /* you shouldn't be able to change a file's type with setattr */
207 if (valid & OBD_MD_FLTYPE) {
208 attr->ia_mode = (attr->ia_mode & ~S_IFMT)|(oa->o_mode & S_IFMT);
209 attr->ia_valid |= ATTR_MODE;
212 if (valid & OBD_MD_FLMODE) {
213 attr->ia_mode = (attr->ia_mode & S_IFMT)|(oa->o_mode & ~S_IFMT);
214 attr->ia_valid |= ATTR_MODE;
215 if (!cfs_curproc_is_in_groups(oa->o_gid) &&
216 !cfs_capable(CFS_CAP_FSETID))
217 attr->ia_mode &= ~S_ISGID;
219 if (valid & OBD_MD_FLUID) {
220 attr->ia_uid = oa->o_uid;
221 attr->ia_valid |= ATTR_UID;
223 if (valid & OBD_MD_FLGID) {
224 attr->ia_gid = oa->o_gid;
225 attr->ia_valid |= ATTR_GID;
228 EXPORT_SYMBOL(iattr_from_obdo);
230 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid)
232 iattr_from_obdo(&op_data->op_attr, oa, valid);
233 if (valid & OBD_MD_FLBLOCKS) {
234 op_data->op_attr_blocks = oa->o_blocks;
235 op_data->op_attr.ia_valid |= ATTR_BLOCKS;
237 if (valid & OBD_MD_FLFLAGS) {
238 ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags =
240 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
243 EXPORT_SYMBOL(md_from_obdo);
245 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
248 obdo_from_iattr(oa, &op_data->op_attr, valid);
249 if (valid & ATTR_BLOCKS) {
250 oa->o_blocks = op_data->op_attr_blocks;
251 oa->o_valid |= OBD_MD_FLBLOCKS;
253 if (valid & ATTR_ATTR_FLAG) {
255 ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags;
256 oa->o_valid |= OBD_MD_FLFLAGS;
259 EXPORT_SYMBOL(obdo_from_md);