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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * Implementation of cl_page for LOV layer.
33 * Author: Nikita Danilov <nikita.danilov@sun.com>
34 * Author: Jinshan Xiong <jinshan.xiong@intel.com>
37 #define DEBUG_SUBSYSTEM S_LOV
39 #include "lov_cl_internal.h"
40 #include <linux/bug.h>
41 #include <linux/compiler.h>
48 * Lov page operations.
50 int lov_page_init_composite(const struct lu_env *env, struct cl_object *obj,
51 struct cl_page *page, pgoff_t index)
53 struct lov_object *loo = cl2lov(obj);
54 struct lov_io *lio = lov_env_io(env);
55 struct cl_object *subobj;
57 struct lov_io_sub *sub;
58 struct lov_layout_raid0 *r0;
61 bool stripe_cached = false;
68 /* Direct i/o (CPT_TRANSIENT) is split strictly to stripes, so we can
69 * cache the stripe information. Buffered i/o is differently
70 * organized, and stripe calculation isn't a significant cost for
71 * buffered i/o, so we only cache this for direct i/o.
73 stripe_cached = lio->lis_cached_entry != LIS_CACHE_ENTRY_NONE &&
74 page->cp_type == CPT_TRANSIENT;
76 offset = index << PAGE_SHIFT;
79 entry = lio->lis_cached_entry;
80 stripe = lio->lis_cached_stripe;
81 /* Offset can never go backwards in an i/o, so this is valid */
82 suboff = lio->lis_cached_suboff + offset - lio->lis_cached_off;
84 entry = lov_io_layout_at(lio, offset);
88 stripe = lov_stripe_number(loo->lo_lsm, entry, offset);
89 rc = lov_stripe_offset(loo->lo_lsm, entry, offset, stripe,
92 lio->lis_cached_entry = entry;
93 lio->lis_cached_stripe = stripe;
94 lio->lis_cached_off = offset;
95 lio->lis_cached_suboff = suboff;
98 if (entry < 0 || !lsm_entry_inited(loo->lo_lsm, entry)) {
99 /* non-existing layout component */
100 lov_page_init_empty(env, obj, page, index);
104 CDEBUG(D_PAGE, "offset %llu, entry %d, stripe %d, suboff %llu\n",
105 offset, entry, stripe, suboff);
107 page->cp_lov_index = lov_comp_index(entry, stripe);
108 LASSERT(page->cp_lov_index != CP_LOV_INDEX_EMPTY);
110 if (!stripe_cached) {
111 sub = lov_sub_get(env, lio, page->cp_lov_index);
113 RETURN(PTR_ERR(sub));
115 sub = lio->lis_cached_sub;
118 lio->lis_cached_sub = sub;
120 r0 = lov_r0(loo, entry);
121 LASSERT(stripe < r0->lo_nr);
123 subobj = lovsub2cl(r0->lo_sub[stripe]);
124 cl_object_for_each(o, subobj) {
125 if (o->co_ops->coo_page_init) {
126 rc = o->co_ops->coo_page_init(sub->sub_env, o, page,
127 suboff >> PAGE_SHIFT);
136 int lov_page_init_empty(const struct lu_env *env, struct cl_object *obj,
137 struct cl_page *cl_page, pgoff_t index)
142 BUILD_BUG_ON(!__same_type(cl_page->cp_lov_index, CP_LOV_INDEX_EMPTY));
143 cl_page->cp_lov_index = CP_LOV_INDEX_EMPTY;
145 addr = kmap(cl_page->cp_vmpage);
146 memset(addr, 0, PAGE_SIZE);
147 kunmap(cl_page->cp_vmpage);
148 SetPageUptodate(cl_page->cp_vmpage);
152 int lov_page_init_foreign(const struct lu_env *env, struct cl_object *obj,
153 struct cl_page *page, pgoff_t index)
155 CDEBUG(D_PAGE, DFID" has no data\n", PFID(lu_object_fid(&obj->co_lu)));