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 [sun.com URL with a
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 CLASSERT(sizeof(struct lustre_handle) +
60 sizeof(struct llog_cookie) <= sizeof(src->o_inline));
62 CDEBUG(D_INODE, "src obdo "LPX64" valid "LPX64", dst obdo "LPX64"\n",
63 src->o_id, src->o_valid, dst->o_id);
65 if (valid & OBD_MD_FLATIME)
66 dst->o_atime = src->o_atime;
67 if (valid & OBD_MD_FLMTIME)
68 dst->o_mtime = src->o_mtime;
69 if (valid & OBD_MD_FLCTIME)
70 dst->o_ctime = src->o_ctime;
71 if (valid & OBD_MD_FLSIZE)
72 dst->o_size = src->o_size;
73 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
74 dst->o_blocks = src->o_blocks;
75 if (valid & OBD_MD_FLBLKSZ)
76 dst->o_blksize = src->o_blksize;
77 if (valid & OBD_MD_FLTYPE)
78 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
79 if (valid & OBD_MD_FLMODE)
80 dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
81 if (valid & OBD_MD_FLUID)
82 dst->o_uid = src->o_uid;
83 if (valid & OBD_MD_FLGID)
84 dst->o_gid = src->o_gid;
85 if (valid & OBD_MD_FLFLAGS)
86 dst->o_flags = src->o_flags;
87 if (valid & OBD_MD_FLGENER)
88 dst->o_generation = src->o_generation;
89 if (valid & OBD_MD_FLINLINE)
90 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
92 dst->o_valid |= valid;
94 EXPORT_SYMBOL(obdo_cpy_md);
96 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
97 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare)
101 if ( compare & OBD_MD_FLATIME )
102 res = (res || (dst->o_atime != src->o_atime));
103 if ( compare & OBD_MD_FLMTIME )
104 res = (res || (dst->o_mtime != src->o_mtime));
105 if ( compare & OBD_MD_FLCTIME )
106 res = (res || (dst->o_ctime != src->o_ctime));
107 if ( compare & OBD_MD_FLSIZE )
108 res = (res || (dst->o_size != src->o_size));
109 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
110 res = (res || (dst->o_blocks != src->o_blocks));
111 if ( compare & OBD_MD_FLBLKSZ )
112 res = (res || (dst->o_blksize != src->o_blksize));
113 if ( compare & OBD_MD_FLTYPE )
114 res = (res || (((dst->o_mode ^ src->o_mode) & S_IFMT) != 0));
115 if ( compare & OBD_MD_FLMODE )
116 res = (res || (((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0));
117 if ( compare & OBD_MD_FLUID )
118 res = (res || (dst->o_uid != src->o_uid));
119 if ( compare & OBD_MD_FLGID )
120 res = (res || (dst->o_gid != src->o_gid));
121 if ( compare & OBD_MD_FLFLAGS )
122 res = (res || (dst->o_flags != src->o_flags));
123 if ( compare & OBD_MD_FLNLINK )
124 res = (res || (dst->o_nlink != src->o_nlink));
125 if ( compare & OBD_MD_FLGENER )
126 res = (res || (dst->o_generation != src->o_generation));
127 /* XXX Don't know if thses should be included here - wasn't previously
128 if ( compare & OBD_MD_FLINLINE )
129 res = (res || memcmp(dst->o_inline, src->o_inline));
133 EXPORT_SYMBOL(obdo_cmp_md);
135 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj)
137 ioobj->ioo_id = oa->o_id;
138 if (oa->o_valid & OBD_MD_FLGROUP)
139 ioobj->ioo_gr = oa->o_gr;
142 ioobj->ioo_type = oa->o_mode;
144 EXPORT_SYMBOL(obdo_to_ioobj);
146 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned int ia_valid)
148 if (ia_valid & ATTR_ATIME) {
149 oa->o_atime = LTIME_S(attr->ia_atime);
150 oa->o_valid |= OBD_MD_FLATIME;
152 if (ia_valid & ATTR_MTIME) {
153 oa->o_mtime = LTIME_S(attr->ia_mtime);
154 oa->o_valid |= OBD_MD_FLMTIME;
156 if (ia_valid & ATTR_CTIME) {
157 oa->o_ctime = LTIME_S(attr->ia_ctime);
158 oa->o_valid |= OBD_MD_FLCTIME;
160 if (ia_valid & ATTR_SIZE) {
161 oa->o_size = attr->ia_size;
162 oa->o_valid |= OBD_MD_FLSIZE;
164 if (ia_valid & ATTR_MODE) {
165 oa->o_mode = attr->ia_mode;
166 oa->o_valid |= OBD_MD_FLTYPE | OBD_MD_FLMODE;
167 if (!in_group_p(oa->o_gid) && !capable(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 (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
216 attr->ia_mode &= ~S_ISGID;
218 if (valid & OBD_MD_FLUID) {
219 attr->ia_uid = oa->o_uid;
220 attr->ia_valid |= ATTR_UID;
222 if (valid & OBD_MD_FLGID) {
223 attr->ia_gid = oa->o_gid;
224 attr->ia_valid |= ATTR_GID;
227 EXPORT_SYMBOL(iattr_from_obdo);
229 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid)
231 iattr_from_obdo(&op_data->op_attr, oa, valid);
232 if (valid & OBD_MD_FLBLOCKS) {
233 op_data->op_attr_blocks = oa->o_blocks;
234 op_data->op_attr.ia_valid |= ATTR_BLOCKS;
236 if (valid & OBD_MD_FLFLAGS) {
237 ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags =
239 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
242 EXPORT_SYMBOL(md_from_obdo);
244 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
247 obdo_from_iattr(oa, &op_data->op_attr, valid);
248 if (valid & ATTR_BLOCKS) {
249 oa->o_blocks = op_data->op_attr_blocks;
250 oa->o_valid |= OBD_MD_FLBLOCKS;
252 if (valid & ATTR_ATTR_FLAG) {
254 ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags;
255 oa->o_valid |= OBD_MD_FLFLAGS;
258 EXPORT_SYMBOL(obdo_from_md);