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 <obd_class.h>
42 #include <uapi/linux/lustre/lustre_idl.h>
43 #include <lustre_obdo.h>
45 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent)
47 dst->o_parent_oid = fid_oid(parent);
48 dst->o_parent_seq = fid_seq(parent);
49 dst->o_parent_ver = fid_ver(parent);
50 dst->o_valid |= OBD_MD_FLGENER | OBD_MD_FLFID;
52 EXPORT_SYMBOL(obdo_set_parent_fid);
54 /* WARNING: the file systems must take care not to tinker with
55 * attributes they don't manage (such as blocks).
57 void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid)
61 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
62 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
63 valid, LTIME_S(src->i_mtime),
64 LTIME_S(src->i_ctime));
66 if (valid & OBD_MD_FLATIME) {
67 dst->o_atime = LTIME_S(src->i_atime);
68 newvalid |= OBD_MD_FLATIME;
70 if (valid & OBD_MD_FLMTIME) {
71 dst->o_mtime = LTIME_S(src->i_mtime);
72 newvalid |= OBD_MD_FLMTIME;
74 if (valid & OBD_MD_FLCTIME) {
75 dst->o_ctime = LTIME_S(src->i_ctime);
76 newvalid |= OBD_MD_FLCTIME;
78 if (valid & OBD_MD_FLSIZE) {
79 dst->o_size = i_size_read(src);
80 newvalid |= OBD_MD_FLSIZE;
82 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
83 dst->o_blocks = src->i_blocks;
84 newvalid |= OBD_MD_FLBLOCKS;
86 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
87 dst->o_blksize = 1 << src->i_blkbits;
88 newvalid |= OBD_MD_FLBLKSZ;
90 if (valid & OBD_MD_FLTYPE) {
91 dst->o_mode = (dst->o_mode & S_IALLUGO) |
92 (src->i_mode & S_IFMT);
93 newvalid |= OBD_MD_FLTYPE;
95 if (valid & OBD_MD_FLMODE) {
96 dst->o_mode = (dst->o_mode & S_IFMT) |
97 (src->i_mode & S_IALLUGO);
98 newvalid |= OBD_MD_FLMODE;
100 if (valid & OBD_MD_FLUID) {
101 dst->o_uid = from_kuid(&init_user_ns, src->i_uid);
102 newvalid |= OBD_MD_FLUID;
104 if (valid & OBD_MD_FLGID) {
105 dst->o_gid = from_kgid(&init_user_ns, src->i_gid);
106 newvalid |= OBD_MD_FLGID;
108 if (valid & OBD_MD_FLFLAGS) {
109 dst->o_flags = src->i_flags;
110 newvalid |= OBD_MD_FLFLAGS;
112 dst->o_valid |= newvalid;
114 EXPORT_SYMBOL(obdo_from_inode);
116 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj)
118 ioobj->ioo_oid = oa->o_oi;
119 if (unlikely(!(oa->o_valid & OBD_MD_FLGROUP)))
120 ostid_set_seq_mdt0(&ioobj->ioo_oid);
122 /* Since 2.4 this does not contain o_mode in the low 16 bits.
123 * Instead, it holds (bd_md_max_brw - 1) for multi-bulk BRW RPCs
125 ioobj->ioo_max_brw = 0;
127 EXPORT_SYMBOL(obdo_to_ioobj);
130 * Create an obdo to send over the wire
132 void lustre_set_wire_obdo(const struct obd_connect_data *ocd,
133 struct obdo *wobdo, const struct obdo *lobdo)
136 wobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
140 if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
141 fid_seq_is_echo(ostid_seq(&lobdo->o_oi))) {
143 * Currently OBD_FL_OSTID will only be used when 2.4 echo
144 * client communicate with pre-2.4 server
146 wobdo->o_oi.oi.oi_id = fid_oid(&lobdo->o_oi.oi_fid);
147 wobdo->o_oi.oi.oi_seq = fid_seq(&lobdo->o_oi.oi_fid);
150 EXPORT_SYMBOL(lustre_set_wire_obdo);
153 * Create a local obdo from a wire based odbo
155 void lustre_get_wire_obdo(const struct obd_connect_data *ocd,
156 struct obdo *lobdo, const struct obdo *wobdo)
160 if (lobdo->o_valid & OBD_MD_FLFLAGS)
161 local_flags = lobdo->o_flags & OBD_FL_LOCAL_MASK;
165 lobdo->o_valid |= OBD_MD_FLFLAGS;
166 lobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
167 lobdo->o_flags |= local_flags;
172 if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
173 fid_seq_is_echo(wobdo->o_oi.oi.oi_seq)) {
175 lobdo->o_oi.oi_fid.f_seq = wobdo->o_oi.oi.oi_seq;
176 lobdo->o_oi.oi_fid.f_oid = wobdo->o_oi.oi.oi_id;
177 lobdo->o_oi.oi_fid.f_ver = 0;
180 EXPORT_SYMBOL(lustre_get_wire_obdo);