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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
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 #include "../include/obd_class.h"
46 #include "../include/lustre/lustre_idl.h"
48 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent)
50 dst->o_parent_oid = fid_oid(parent);
51 dst->o_parent_seq = fid_seq(parent);
52 dst->o_parent_ver = fid_ver(parent);
53 dst->o_valid |= OBD_MD_FLGENER | OBD_MD_FLFID;
55 EXPORT_SYMBOL(obdo_set_parent_fid);
57 /* WARNING: the file systems must take care not to tinker with
58 * attributes they don't manage (such as blocks).
60 void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid)
64 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
65 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
66 valid, LTIME_S(src->i_mtime),
67 LTIME_S(src->i_ctime));
69 if (valid & OBD_MD_FLATIME) {
70 dst->o_atime = LTIME_S(src->i_atime);
71 newvalid |= OBD_MD_FLATIME;
73 if (valid & OBD_MD_FLMTIME) {
74 dst->o_mtime = LTIME_S(src->i_mtime);
75 newvalid |= OBD_MD_FLMTIME;
77 if (valid & OBD_MD_FLCTIME) {
78 dst->o_ctime = LTIME_S(src->i_ctime);
79 newvalid |= OBD_MD_FLCTIME;
81 if (valid & OBD_MD_FLSIZE) {
82 dst->o_size = i_size_read(src);
83 newvalid |= OBD_MD_FLSIZE;
85 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
86 dst->o_blocks = src->i_blocks;
87 newvalid |= OBD_MD_FLBLOCKS;
89 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
90 dst->o_blksize = 1 << src->i_blkbits;
91 newvalid |= OBD_MD_FLBLKSZ;
93 if (valid & OBD_MD_FLTYPE) {
94 dst->o_mode = (dst->o_mode & S_IALLUGO) |
95 (src->i_mode & S_IFMT);
96 newvalid |= OBD_MD_FLTYPE;
98 if (valid & OBD_MD_FLMODE) {
99 dst->o_mode = (dst->o_mode & S_IFMT) |
100 (src->i_mode & S_IALLUGO);
101 newvalid |= OBD_MD_FLMODE;
103 if (valid & OBD_MD_FLUID) {
104 dst->o_uid = from_kuid(&init_user_ns, src->i_uid);
105 newvalid |= OBD_MD_FLUID;
107 if (valid & OBD_MD_FLGID) {
108 dst->o_gid = from_kgid(&init_user_ns, src->i_gid);
109 newvalid |= OBD_MD_FLGID;
111 if (valid & OBD_MD_FLFLAGS) {
112 dst->o_flags = src->i_flags;
113 newvalid |= OBD_MD_FLFLAGS;
115 dst->o_valid |= newvalid;
117 EXPORT_SYMBOL(obdo_from_inode);
119 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj)
121 ioobj->ioo_oid = oa->o_oi;
122 if (unlikely(!(oa->o_valid & OBD_MD_FLGROUP)))
123 ostid_set_seq_mdt0(&ioobj->ioo_oid);
125 /* Since 2.4 this does not contain o_mode in the low 16 bits.
126 * Instead, it holds (bd_md_max_brw - 1) for multi-bulk BRW RPCs
128 ioobj->ioo_max_brw = 0;
130 EXPORT_SYMBOL(obdo_to_ioobj);
132 static void iattr_from_obdo(struct iattr *attr, struct obdo *oa, u32 valid)
134 valid &= oa->o_valid;
136 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
137 CDEBUG(D_INODE, "valid %#llx, new time %llu/%llu\n",
138 oa->o_valid, oa->o_mtime, oa->o_ctime);
141 if (valid & OBD_MD_FLATIME) {
142 LTIME_S(attr->ia_atime) = oa->o_atime;
143 attr->ia_valid |= ATTR_ATIME;
145 if (valid & OBD_MD_FLMTIME) {
146 LTIME_S(attr->ia_mtime) = oa->o_mtime;
147 attr->ia_valid |= ATTR_MTIME;
149 if (valid & OBD_MD_FLCTIME) {
150 LTIME_S(attr->ia_ctime) = oa->o_ctime;
151 attr->ia_valid |= ATTR_CTIME;
153 if (valid & OBD_MD_FLSIZE) {
154 attr->ia_size = oa->o_size;
155 attr->ia_valid |= ATTR_SIZE;
157 #if 0 /* you shouldn't be able to change a file's type with setattr */
158 if (valid & OBD_MD_FLTYPE) {
159 attr->ia_mode = (attr->ia_mode & ~S_IFMT)|(oa->o_mode & S_IFMT);
160 attr->ia_valid |= ATTR_MODE;
163 if (valid & OBD_MD_FLMODE) {
164 attr->ia_mode = (attr->ia_mode & S_IFMT)|(oa->o_mode & ~S_IFMT);
165 attr->ia_valid |= ATTR_MODE;
166 if (!in_group_p(make_kgid(&init_user_ns, oa->o_gid)) &&
167 !capable(CFS_CAP_FSETID))
168 attr->ia_mode &= ~S_ISGID;
170 if (valid & OBD_MD_FLUID) {
171 attr->ia_uid = make_kuid(&init_user_ns, oa->o_uid);
172 attr->ia_valid |= ATTR_UID;
174 if (valid & OBD_MD_FLGID) {
175 attr->ia_gid = make_kgid(&init_user_ns, oa->o_gid);
176 attr->ia_valid |= ATTR_GID;
180 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid)
182 iattr_from_obdo(&op_data->op_attr, oa, valid);
183 if (valid & OBD_MD_FLBLOCKS) {
184 op_data->op_attr_blocks = oa->o_blocks;
185 op_data->op_attr.ia_valid |= ATTR_BLOCKS;
187 if (valid & OBD_MD_FLFLAGS) {
188 op_data->op_attr_flags = oa->o_flags;
189 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
192 EXPORT_SYMBOL(md_from_obdo);