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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2015, Intel Corporation.
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
43 #include <linux/user_namespace.h>
44 #ifdef HAVE_UIDGID_HEADER
45 # include <linux/uidgid.h>
47 #include <libcfs/libcfs.h>
50 #include "llite_internal.h"
51 #include "vvp_internal.h"
53 /*****************************************************************************
59 int vvp_object_invariant(const struct cl_object *obj)
61 struct inode *inode = vvp_object_inode(obj);
62 struct ll_inode_info *lli = ll_i2info(inode);
64 return (S_ISREG(inode->i_mode) || inode->i_mode == 0) &&
68 static int vvp_object_print(const struct lu_env *env, void *cookie,
69 lu_printer_t p, const struct lu_object *o)
71 struct vvp_object *obj = lu2vvp(o);
72 struct inode *inode = obj->vob_inode;
73 struct ll_inode_info *lli;
75 (*p)(env, cookie, "(%d %d) inode: %p ",
76 atomic_read(&obj->vob_transient_pages),
77 atomic_read(&obj->vob_mmap_cnt),
80 lli = ll_i2info(inode);
81 (*p)(env, cookie, "%lu/%u %o %u %d %p "DFID,
82 inode->i_ino, inode->i_generation, inode->i_mode,
83 inode->i_nlink, atomic_read(&inode->i_count),
84 lli->lli_clob, PFID(&lli->lli_fid));
89 static int vvp_attr_get(const struct lu_env *env, struct cl_object *obj,
92 struct inode *inode = vvp_object_inode(obj);
95 * lov overwrites most of these fields in
96 * lov_attr_get()->...lov_merge_lvb_kms(), except when inode
97 * attributes are newer.
100 attr->cat_size = i_size_read(inode);
101 attr->cat_mtime = LTIME_S(inode->i_mtime);
102 attr->cat_atime = LTIME_S(inode->i_atime);
103 attr->cat_ctime = LTIME_S(inode->i_ctime);
104 attr->cat_blocks = inode->i_blocks;
105 attr->cat_uid = from_kuid(&init_user_ns, inode->i_uid);
106 attr->cat_gid = from_kgid(&init_user_ns, inode->i_gid);
107 /* KMS is not known by this layer */
108 return 0; /* layers below have to fill in the rest */
111 static int vvp_attr_update(const struct lu_env *env, struct cl_object *obj,
112 const struct cl_attr *attr, unsigned valid)
114 struct inode *inode = vvp_object_inode(obj);
117 inode->i_uid = make_kuid(&init_user_ns, attr->cat_uid);
119 inode->i_gid = make_kgid(&init_user_ns, attr->cat_gid);
120 if (valid & CAT_ATIME)
121 LTIME_S(inode->i_atime) = attr->cat_atime;
122 if (valid & CAT_MTIME)
123 LTIME_S(inode->i_mtime) = attr->cat_mtime;
124 if (valid & CAT_CTIME)
125 LTIME_S(inode->i_ctime) = attr->cat_ctime;
126 if (0 && valid & CAT_SIZE)
127 i_size_write(inode, attr->cat_size);
128 /* not currently necessary */
129 if (0 && valid & (CAT_UID|CAT_GID|CAT_SIZE))
130 mark_inode_dirty(inode);
134 static int vvp_conf_set(const struct lu_env *env, struct cl_object *obj,
135 const struct cl_object_conf *conf)
137 struct ll_inode_info *lli = ll_i2info(conf->coc_inode);
139 if (conf->coc_opc == OBJECT_CONF_INVALIDATE) {
140 CDEBUG(D_VFSTRACE, DFID ": losing layout lock\n",
141 PFID(&lli->lli_fid));
143 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
145 /* Clean up page mmap for this inode.
146 * The reason for us to do this is that if the page has
147 * already been installed into memory space, the process
148 * can access it without interacting with lustre, so this
149 * page may be stale due to layout change, and the process
150 * will never be notified.
151 * This operation is expensive but mmap processes have to pay
152 * a price themselves. */
153 unmap_mapping_range(conf->coc_inode->i_mapping,
154 0, OBD_OBJECT_EOF, 0);
159 static int vvp_prune(const struct lu_env *env, struct cl_object *obj)
161 struct inode *inode = vvp_object_inode(obj);
165 rc = cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, CL_FSYNC_LOCAL, 1);
167 CDEBUG(D_VFSTRACE, DFID ": writeback failed: %d\n",
168 PFID(lu_object_fid(&obj->co_lu)), rc);
172 truncate_inode_pages(inode->i_mapping, 0);
176 static int vvp_object_glimpse(const struct lu_env *env,
177 const struct cl_object *obj, struct ost_lvb *lvb)
179 struct inode *inode = vvp_object_inode(obj);
182 lvb->lvb_mtime = LTIME_S(inode->i_mtime);
183 lvb->lvb_atime = LTIME_S(inode->i_atime);
184 lvb->lvb_ctime = LTIME_S(inode->i_ctime);
187 * LU-417: Add dirty pages block count lest i_blocks reports 0, some
188 * "cp" or "tar" on remote node may think it's a completely sparse file
191 if (lvb->lvb_size > 0 && lvb->lvb_blocks == 0)
192 lvb->lvb_blocks = dirty_cnt(inode);
197 static void vvp_req_attr_set(const struct lu_env *env, struct cl_object *obj,
198 struct cl_req_attr *attr)
202 u64 valid_flags = OBD_MD_FLTYPE;
205 inode = vvp_object_inode(obj);
207 if (attr->cra_type == CRT_WRITE)
208 valid_flags |= OBD_MD_FLMTIME | OBD_MD_FLCTIME |
209 OBD_MD_FLUID | OBD_MD_FLGID;
210 obdo_from_inode(oa, inode, valid_flags & attr->cra_flags);
211 obdo_set_parent_fid(oa, &ll_i2info(inode)->lli_fid);
212 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_INVALID_PFID))
214 memcpy(attr->cra_jobid, ll_i2info(inode)->lli_jobid, LUSTRE_JOBID_SIZE);
217 static const struct cl_object_operations vvp_ops = {
218 .coo_page_init = vvp_page_init,
219 .coo_lock_init = vvp_lock_init,
220 .coo_io_init = vvp_io_init,
221 .coo_attr_get = vvp_attr_get,
222 .coo_attr_update = vvp_attr_update,
223 .coo_conf_set = vvp_conf_set,
224 .coo_prune = vvp_prune,
225 .coo_glimpse = vvp_object_glimpse,
226 .coo_req_attr_set = vvp_req_attr_set
229 static int vvp_object_init0(const struct lu_env *env,
230 struct vvp_object *vob,
231 const struct cl_object_conf *conf)
233 vob->vob_inode = conf->coc_inode;
234 atomic_set(&vob->vob_transient_pages, 0);
235 cl_object_page_init(&vob->vob_cl, sizeof(struct vvp_page));
239 static int vvp_object_init(const struct lu_env *env, struct lu_object *obj,
240 const struct lu_object_conf *conf)
242 struct vvp_device *dev = lu2vvp_dev(obj->lo_dev);
243 struct vvp_object *vob = lu2vvp(obj);
244 struct lu_object *below;
245 struct lu_device *under;
248 under = &dev->vdv_next->cd_lu_dev;
249 below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
251 const struct cl_object_conf *cconf;
253 cconf = lu2cl_conf(conf);
254 lu_object_add(obj, below);
255 result = vvp_object_init0(env, vob, cconf);
262 static void vvp_object_free(const struct lu_env *env, struct lu_object *obj)
264 struct vvp_object *vob = lu2vvp(obj);
267 lu_object_header_fini(obj->lo_header);
268 OBD_SLAB_FREE_PTR(vob, vvp_object_kmem);
271 static const struct lu_object_operations vvp_lu_obj_ops = {
272 .loo_object_init = vvp_object_init,
273 .loo_object_free = vvp_object_free,
274 .loo_object_print = vvp_object_print,
277 struct vvp_object *cl_inode2vvp(struct inode *inode)
279 struct ll_inode_info *lli = ll_i2info(inode);
280 struct cl_object *obj = lli->lli_clob;
281 struct lu_object *lu;
283 LASSERT(obj != NULL);
284 lu = lu_object_locate(obj->co_lu.lo_header, &vvp_device_type);
290 struct lu_object *vvp_object_alloc(const struct lu_env *env,
291 const struct lu_object_header *unused,
292 struct lu_device *dev)
294 struct vvp_object *vob;
295 struct lu_object *obj;
297 OBD_SLAB_ALLOC_PTR_GFP(vob, vvp_object_kmem, GFP_NOFS);
299 struct cl_object_header *hdr;
301 obj = &vob->vob_cl.co_lu;
302 hdr = &vob->vob_header;
303 cl_object_header_init(hdr);
304 hdr->coh_page_bufsize = cfs_size_round(sizeof(struct cl_page));
306 lu_object_init(obj, &hdr->coh_lu, dev);
307 lu_object_add_top(&hdr->coh_lu, obj);
309 vob->vob_cl.co_ops = &vvp_ops;
310 obj->lo_ops = &vvp_lu_obj_ops;