1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * cl_object implementation for VVP layer.
38 * Author: Nikita Danilov <nikita.danilov@sun.com>
41 #define DEBUG_SUBSYSTEM S_LLITE
44 # error This file is kernel only.
47 #include <libcfs/libcfs.h>
50 #include <lustre_lite.h>
52 #include "vvp_internal.h"
54 /*****************************************************************************
60 static int vvp_object_print(const struct lu_env *env, void *cookie,
61 lu_printer_t p, const struct lu_object *o)
63 struct ccc_object *obj = lu2ccc(o);
64 struct inode *inode = obj->cob_inode;
65 struct ll_inode_info *lli;
67 (*p)(env, cookie, "(%s %i %i) inode: %p ",
68 list_empty(&obj->cob_pending_list) ? "-" : "+",
69 obj->cob_transient_pages, atomic_read(&obj->cob_mmap_cnt), inode);
71 lli = ll_i2info(inode);
72 (*p)(env, cookie, "%lu/%u %o %u %i %p "DFID,
73 inode->i_ino, inode->i_generation, inode->i_mode,
74 inode->i_nlink, atomic_read(&inode->i_count),
75 lli->lli_clob, PFID(&lli->lli_fid));
80 static int vvp_attr_get(const struct lu_env *env, struct cl_object *obj,
83 struct inode *inode = ccc_object_inode(obj);
86 * lov overwrites most of these fields in
87 * lov_attr_get()->...lov_merge_lvb_kms(), except when inode
88 * attributes are newer.
91 attr->cat_size = i_size_read(inode);
92 attr->cat_mtime = LTIME_S(inode->i_mtime);
93 attr->cat_atime = LTIME_S(inode->i_atime);
94 attr->cat_ctime = LTIME_S(inode->i_ctime);
95 attr->cat_blocks = inode->i_blocks;
96 attr->cat_uid = inode->i_uid;
97 attr->cat_gid = inode->i_gid;
98 /* KMS is not known by this layer */
99 return 0; /* layers below have to fill in the rest */
102 static int vvp_attr_set(const struct lu_env *env, struct cl_object *obj,
103 const struct cl_attr *attr, unsigned valid)
105 struct inode *inode = ccc_object_inode(obj);
108 inode->i_uid = attr->cat_uid;
110 inode->i_gid = attr->cat_gid;
111 if (0 && valid & CAT_SIZE)
112 i_size_write(inode, attr->cat_size);
113 /* not currently necessary */
114 if (0 && valid & (CAT_UID|CAT_GID|CAT_SIZE))
115 mark_inode_dirty(inode);
119 static const struct cl_object_operations vvp_ops = {
120 .coo_page_init = vvp_page_init,
121 .coo_lock_init = vvp_lock_init,
122 .coo_io_init = vvp_io_init,
123 .coo_attr_get = vvp_attr_get,
124 .coo_attr_set = vvp_attr_set,
125 .coo_conf_set = ccc_conf_set,
126 .coo_glimpse = ccc_object_glimpse
129 static const struct lu_object_operations vvp_lu_obj_ops = {
130 .loo_object_init = ccc_object_init,
131 .loo_object_free = ccc_object_free,
132 .loo_object_print = vvp_object_print
135 struct ccc_object *cl_inode2ccc(struct inode *inode)
137 struct cl_inode_info *lli = cl_i2info(inode);
138 struct cl_object *obj = lli->lli_clob;
139 struct lu_object *lu;
141 LASSERT(obj != NULL);
142 lu = lu_object_locate(obj->co_lu.lo_header, &vvp_device_type);
147 struct lu_object *vvp_object_alloc(const struct lu_env *env,
148 const struct lu_object_header *hdr,
149 struct lu_device *dev)
151 return ccc_object_alloc(env, hdr, dev, &vvp_ops, &vvp_lu_obj_ops);