linux/drivers/staging/lustre/lustre/obdclass/obdo.c
<<
>>
Prefs
   1/*
   2 * GPL HEADER START
   3 *
   4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5 *
   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.
   9 *
  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).
  15 *
  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
  19 *
  20 * GPL HEADER END
  21 */
  22/*
  23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24 * Use is subject to license terms.
  25 *
  26 * Copyright (c) 2011, 2012, Intel Corporation.
  27 */
  28/*
  29 * This file is part of Lustre, http://www.lustre.org/
  30 * Lustre is a trademark of Sun Microsystems, Inc.
  31 *
  32 * lustre/obdclass/obdo.c
  33 *
  34 * Object Devices Class Driver
  35 * These are the only exported functions, they provide some generic
  36 * infrastructure for managing object devices
  37 */
  38
  39#define DEBUG_SUBSYSTEM S_CLASS
  40
  41#include "../include/obd_class.h"
  42#include "../include/lustre/lustre_idl.h"
  43#include "../include/lustre_obdo.h"
  44
  45void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent)
  46{
  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;
  51}
  52EXPORT_SYMBOL(obdo_set_parent_fid);
  53
  54/* WARNING: the file systems must take care not to tinker with
  55 * attributes they don't manage (such as blocks).
  56 */
  57void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid)
  58{
  59        u32 newvalid = 0;
  60
  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));
  65
  66        if (valid & OBD_MD_FLATIME) {
  67                dst->o_atime = LTIME_S(src->i_atime);
  68                newvalid |= OBD_MD_FLATIME;
  69        }
  70        if (valid & OBD_MD_FLMTIME) {
  71                dst->o_mtime = LTIME_S(src->i_mtime);
  72                newvalid |= OBD_MD_FLMTIME;
  73        }
  74        if (valid & OBD_MD_FLCTIME) {
  75                dst->o_ctime = LTIME_S(src->i_ctime);
  76                newvalid |= OBD_MD_FLCTIME;
  77        }
  78        if (valid & OBD_MD_FLSIZE) {
  79                dst->o_size = i_size_read(src);
  80                newvalid |= OBD_MD_FLSIZE;
  81        }
  82        if (valid & OBD_MD_FLBLOCKS) {  /* allocation of space (x512 bytes) */
  83                dst->o_blocks = src->i_blocks;
  84                newvalid |= OBD_MD_FLBLOCKS;
  85        }
  86        if (valid & OBD_MD_FLBLKSZ) {   /* optimal block size */
  87                dst->o_blksize = 1 << src->i_blkbits;
  88                newvalid |= OBD_MD_FLBLKSZ;
  89        }
  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;
  94        }
  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;
  99        }
 100        if (valid & OBD_MD_FLUID) {
 101                dst->o_uid = from_kuid(&init_user_ns, src->i_uid);
 102                newvalid |= OBD_MD_FLUID;
 103        }
 104        if (valid & OBD_MD_FLGID) {
 105                dst->o_gid = from_kgid(&init_user_ns, src->i_gid);
 106                newvalid |= OBD_MD_FLGID;
 107        }
 108        if (valid & OBD_MD_FLFLAGS) {
 109                dst->o_flags = src->i_flags;
 110                newvalid |= OBD_MD_FLFLAGS;
 111        }
 112        dst->o_valid |= newvalid;
 113}
 114EXPORT_SYMBOL(obdo_from_inode);
 115
 116void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj)
 117{
 118        ioobj->ioo_oid = oa->o_oi;
 119        if (unlikely(!(oa->o_valid & OBD_MD_FLGROUP)))
 120                ostid_set_seq_mdt0(&ioobj->ioo_oid);
 121
 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
 124         */
 125        ioobj->ioo_max_brw = 0;
 126}
 127EXPORT_SYMBOL(obdo_to_ioobj);
 128
 129/**
 130 * Create an obdo to send over the wire
 131 */
 132void lustre_set_wire_obdo(const struct obd_connect_data *ocd,
 133                          struct obdo *wobdo, const struct obdo *lobdo)
 134{
 135        *wobdo = *lobdo;
 136        wobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
 137        if (!ocd)
 138                return;
 139
 140        if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
 141            fid_seq_is_echo(ostid_seq(&lobdo->o_oi))) {
 142                /*
 143                 * Currently OBD_FL_OSTID will only be used when 2.4 echo
 144                 * client communicate with pre-2.4 server
 145                 */
 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);
 148        }
 149}
 150EXPORT_SYMBOL(lustre_set_wire_obdo);
 151
 152/**
 153 * Create a local obdo from a wire based odbo
 154 */
 155void lustre_get_wire_obdo(const struct obd_connect_data *ocd,
 156                          struct obdo *lobdo, const struct obdo *wobdo)
 157{
 158        u32 local_flags = 0;
 159
 160        if (lobdo->o_valid & OBD_MD_FLFLAGS)
 161                local_flags = lobdo->o_flags & OBD_FL_LOCAL_MASK;
 162
 163        *lobdo = *wobdo;
 164        if (local_flags) {
 165                lobdo->o_valid |= OBD_MD_FLFLAGS;
 166                lobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
 167                lobdo->o_flags |= local_flags;
 168        }
 169        if (!ocd)
 170                return;
 171
 172        if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
 173            fid_seq_is_echo(wobdo->o_oi.oi.oi_seq)) {
 174                /* see above */
 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;
 178        }
 179}
 180EXPORT_SYMBOL(lustre_get_wire_obdo);
 181