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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2012, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/obdclass/obdo.c
34 * Object Devices Class Driver
35 * These are the only exported functions, they provide some generic
36 * infrastructure for managing object devices
39 #define DEBUG_SUBSYSTEM S_CLASS
41 #include "../include/obd_class.h"
42 #include "../include/lustre/lustre_idl.h"
44 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent)
46 dst->o_parent_oid = fid_oid(parent);
47 dst->o_parent_seq = fid_seq(parent);
48 dst->o_parent_ver = fid_ver(parent);
49 dst->o_valid |= OBD_MD_FLGENER | OBD_MD_FLFID;
51 EXPORT_SYMBOL(obdo_set_parent_fid);
53 /* WARNING: the file systems must take care not to tinker with
54 * attributes they don't manage (such as blocks).
56 void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid)
60 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
61 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
62 valid, LTIME_S(src->i_mtime),
63 LTIME_S(src->i_ctime));
65 if (valid & OBD_MD_FLATIME) {
66 dst->o_atime = LTIME_S(src->i_atime);
67 newvalid |= OBD_MD_FLATIME;
69 if (valid & OBD_MD_FLMTIME) {
70 dst->o_mtime = LTIME_S(src->i_mtime);
71 newvalid |= OBD_MD_FLMTIME;
73 if (valid & OBD_MD_FLCTIME) {
74 dst->o_ctime = LTIME_S(src->i_ctime);
75 newvalid |= OBD_MD_FLCTIME;
77 if (valid & OBD_MD_FLSIZE) {
78 dst->o_size = i_size_read(src);
79 newvalid |= OBD_MD_FLSIZE;
81 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
82 dst->o_blocks = src->i_blocks;
83 newvalid |= OBD_MD_FLBLOCKS;
85 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
86 dst->o_blksize = 1 << src->i_blkbits;
87 newvalid |= OBD_MD_FLBLKSZ;
89 if (valid & OBD_MD_FLTYPE) {
90 dst->o_mode = (dst->o_mode & S_IALLUGO) |
91 (src->i_mode & S_IFMT);
92 newvalid |= OBD_MD_FLTYPE;
94 if (valid & OBD_MD_FLMODE) {
95 dst->o_mode = (dst->o_mode & S_IFMT) |
96 (src->i_mode & S_IALLUGO);
97 newvalid |= OBD_MD_FLMODE;
99 if (valid & OBD_MD_FLUID) {
100 dst->o_uid = from_kuid(&init_user_ns, src->i_uid);
101 newvalid |= OBD_MD_FLUID;
103 if (valid & OBD_MD_FLGID) {
104 dst->o_gid = from_kgid(&init_user_ns, src->i_gid);
105 newvalid |= OBD_MD_FLGID;
107 if (valid & OBD_MD_FLFLAGS) {
108 dst->o_flags = src->i_flags;
109 newvalid |= OBD_MD_FLFLAGS;
111 dst->o_valid |= newvalid;
113 EXPORT_SYMBOL(obdo_from_inode);
115 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj)
117 ioobj->ioo_oid = oa->o_oi;
118 if (unlikely(!(oa->o_valid & OBD_MD_FLGROUP)))
119 ostid_set_seq_mdt0(&ioobj->ioo_oid);
121 /* Since 2.4 this does not contain o_mode in the low 16 bits.
122 * Instead, it holds (bd_md_max_brw - 1) for multi-bulk BRW RPCs
124 ioobj->ioo_max_brw = 0;
126 EXPORT_SYMBOL(obdo_to_ioobj);
128 static void iattr_from_obdo(struct iattr *attr, const struct obdo *oa,
131 valid &= oa->o_valid;
133 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
134 CDEBUG(D_INODE, "valid %#llx, new time %llu/%llu\n",
135 oa->o_valid, oa->o_mtime, oa->o_ctime);
138 if (valid & OBD_MD_FLATIME) {
139 LTIME_S(attr->ia_atime) = oa->o_atime;
140 attr->ia_valid |= ATTR_ATIME;
142 if (valid & OBD_MD_FLMTIME) {
143 LTIME_S(attr->ia_mtime) = oa->o_mtime;
144 attr->ia_valid |= ATTR_MTIME;
146 if (valid & OBD_MD_FLCTIME) {
147 LTIME_S(attr->ia_ctime) = oa->o_ctime;
148 attr->ia_valid |= ATTR_CTIME;
150 if (valid & OBD_MD_FLSIZE) {
151 attr->ia_size = oa->o_size;
152 attr->ia_valid |= ATTR_SIZE;
154 #if 0 /* you shouldn't be able to change a file's type with setattr */
155 if (valid & OBD_MD_FLTYPE) {
156 attr->ia_mode = (attr->ia_mode & ~S_IFMT) |
157 (oa->o_mode & S_IFMT);
158 attr->ia_valid |= ATTR_MODE;
161 if (valid & OBD_MD_FLMODE) {
162 attr->ia_mode = (attr->ia_mode & S_IFMT) |
163 (oa->o_mode & ~S_IFMT);
164 attr->ia_valid |= ATTR_MODE;
165 if (!in_group_p(make_kgid(&init_user_ns, oa->o_gid)) &&
166 !capable(CFS_CAP_FSETID))
167 attr->ia_mode &= ~S_ISGID;
169 if (valid & OBD_MD_FLUID) {
170 attr->ia_uid = make_kuid(&init_user_ns, oa->o_uid);
171 attr->ia_valid |= ATTR_UID;
173 if (valid & OBD_MD_FLGID) {
174 attr->ia_gid = make_kgid(&init_user_ns, oa->o_gid);
175 attr->ia_valid |= ATTR_GID;
179 void md_from_obdo(struct md_op_data *op_data, const struct obdo *oa, u32 valid)
181 iattr_from_obdo(&op_data->op_attr, oa, valid);
182 if (valid & OBD_MD_FLBLOCKS) {
183 op_data->op_attr_blocks = oa->o_blocks;
184 op_data->op_attr.ia_valid |= ATTR_BLOCKS;
186 if (valid & OBD_MD_FLFLAGS) {
187 op_data->op_attr_flags = oa->o_flags;
188 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
191 EXPORT_SYMBOL(md_from_obdo);