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) 2012, 2014, 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 <linux/user_namespace.h>
46 #ifdef HAVE_UIDGID_HEADER
47 # include <linux/uidgid.h>
49 #include <obd_class.h>
50 #include <lustre/lustre_idl.h>
51 #include <lustre_obdo.h>
53 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent)
55 dst->o_parent_oid = fid_oid(parent);
56 dst->o_parent_seq = fid_seq(parent);
57 dst->o_parent_ver = fid_ver(parent);
58 dst->o_valid |= OBD_MD_FLGENER | OBD_MD_FLFID;
60 EXPORT_SYMBOL(obdo_set_parent_fid);
62 /* WARNING: the file systems must take care not to tinker with
63 attributes they don't manage (such as blocks). */
64 void obdo_from_inode(struct obdo *dst, struct inode *src, u64 valid)
68 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
69 CDEBUG(D_INODE, "valid %#llx, new time %lu/%lu\n",
70 valid, LTIME_S(src->i_mtime),
71 LTIME_S(src->i_ctime));
73 if (valid & OBD_MD_FLATIME) {
74 dst->o_atime = LTIME_S(src->i_atime);
75 newvalid |= OBD_MD_FLATIME;
77 if (valid & OBD_MD_FLMTIME) {
78 dst->o_mtime = LTIME_S(src->i_mtime);
79 newvalid |= OBD_MD_FLMTIME;
81 if (valid & OBD_MD_FLCTIME) {
82 dst->o_ctime = LTIME_S(src->i_ctime);
83 newvalid |= OBD_MD_FLCTIME;
85 if (valid & OBD_MD_FLSIZE) {
86 dst->o_size = i_size_read(src);
87 newvalid |= OBD_MD_FLSIZE;
89 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
90 dst->o_blocks = src->i_blocks;
91 newvalid |= OBD_MD_FLBLOCKS;
93 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
94 dst->o_blksize = 1U << src->i_blkbits;
95 newvalid |= OBD_MD_FLBLKSZ;
97 if (valid & OBD_MD_FLTYPE) {
98 dst->o_mode = (dst->o_mode & S_IALLUGO) |
99 (src->i_mode & S_IFMT);
100 newvalid |= OBD_MD_FLTYPE;
102 if (valid & OBD_MD_FLMODE) {
103 dst->o_mode = (dst->o_mode & S_IFMT) |
104 (src->i_mode & S_IALLUGO);
105 newvalid |= OBD_MD_FLMODE;
107 if (valid & OBD_MD_FLUID) {
108 dst->o_uid = from_kuid(&init_user_ns, src->i_uid);
109 newvalid |= OBD_MD_FLUID;
111 if (valid & OBD_MD_FLGID) {
112 dst->o_gid = from_kgid(&init_user_ns, src->i_gid);
113 newvalid |= OBD_MD_FLGID;
115 if (valid & OBD_MD_FLFLAGS) {
116 dst->o_flags = src->i_flags;
117 newvalid |= OBD_MD_FLFLAGS;
119 dst->o_valid |= newvalid;
121 EXPORT_SYMBOL(obdo_from_inode);
123 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid)
125 CDEBUG(D_INODE, "src obdo "DOSTID" valid %#llx, dst obdo "DOSTID"\n",
126 POSTID(&src->o_oi), src->o_valid, POSTID(&dst->o_oi));
127 if (valid & OBD_MD_FLATIME)
128 dst->o_atime = src->o_atime;
129 if (valid & OBD_MD_FLMTIME)
130 dst->o_mtime = src->o_mtime;
131 if (valid & OBD_MD_FLCTIME)
132 dst->o_ctime = src->o_ctime;
133 if (valid & OBD_MD_FLSIZE)
134 dst->o_size = src->o_size;
135 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
136 dst->o_blocks = src->o_blocks;
137 if (valid & OBD_MD_FLBLKSZ)
138 dst->o_blksize = src->o_blksize;
139 if (valid & OBD_MD_FLTYPE)
140 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
141 if (valid & OBD_MD_FLMODE)
142 dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
143 if (valid & OBD_MD_FLUID)
144 dst->o_uid = src->o_uid;
145 if (valid & OBD_MD_FLGID)
146 dst->o_gid = src->o_gid;
147 if (valid & OBD_MD_FLFLAGS)
148 dst->o_flags = src->o_flags;
149 if (valid & OBD_MD_FLFID) {
150 dst->o_parent_seq = src->o_parent_seq;
151 dst->o_parent_ver = src->o_parent_ver;
153 if (valid & OBD_MD_FLGENER)
154 dst->o_parent_oid = src->o_parent_oid;
155 if (valid & OBD_MD_FLHANDLE)
156 dst->o_handle = src->o_handle;
158 dst->o_valid |= valid;
160 EXPORT_SYMBOL(obdo_cpy_md);
162 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj)
164 ioobj->ioo_oid = oa->o_oi;
165 if (unlikely(!(oa->o_valid & OBD_MD_FLGROUP)))
166 ostid_set_seq_mdt0(&ioobj->ioo_oid);
168 /* Since 2.4 this does not contain o_mode in the low 16 bits.
169 * Instead, it holds (bd_md_max_brw - 1) for multi-bulk BRW RPCs */
170 ioobj->ioo_max_brw = 0;
172 EXPORT_SYMBOL(obdo_to_ioobj);
175 * Create an obdo to send over the wire
177 void lustre_set_wire_obdo(const struct obd_connect_data *ocd,
179 const struct obdo *lobdo)
182 wobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
186 if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
187 fid_seq_is_echo(ostid_seq(&lobdo->o_oi))) {
188 /* Currently OBD_FL_OSTID will only be used when 2.4 echo
189 * client communicate with pre-2.4 server */
190 wobdo->o_oi.oi.oi_id = fid_oid(&lobdo->o_oi.oi_fid);
191 wobdo->o_oi.oi.oi_seq = fid_seq(&lobdo->o_oi.oi_fid);
194 EXPORT_SYMBOL(lustre_set_wire_obdo);
197 * Create a local obdo from a wire based odbo
199 void lustre_get_wire_obdo(const struct obd_connect_data *ocd,
201 const struct obdo *wobdo)
203 __u32 local_flags = 0;
205 if (lobdo->o_valid & OBD_MD_FLFLAGS)
206 local_flags = lobdo->o_flags & OBD_FL_LOCAL_MASK;
209 if (local_flags != 0) {
210 lobdo->o_valid |= OBD_MD_FLFLAGS;
211 lobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
212 lobdo->o_flags |= local_flags;
217 if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
218 fid_seq_is_echo(wobdo->o_oi.oi.oi_seq)) {
220 lobdo->o_oi.oi_fid.f_seq = wobdo->o_oi.oi.oi_seq;
221 lobdo->o_oi.oi_fid.f_oid = wobdo->o_oi.oi.oi_id;
222 lobdo->o_oi.oi_fid.f_ver = 0;
225 EXPORT_SYMBOL(lustre_get_wire_obdo);