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>
47 /*****************************************************************************
49 * Lov page operations.
52 int lov_page_init_composite(const struct lu_env *env, struct cl_object *obj,
53 struct cl_page *page, pgoff_t index)
55 struct lov_object *loo = cl2lov(obj);
56 struct lov_io *lio = lov_env_io(env);
57 struct cl_object *subobj;
59 struct lov_io_sub *sub;
60 struct lov_layout_raid0 *r0;
63 bool stripe_cached = false;
70 /* Direct i/o (CPT_TRANSIENT) is split strictly to stripes, so we can
71 * cache the stripe information. Buffered i/o is differently
72 * organized, and stripe calculation isn't a significant cost for
73 * buffered i/o, so we only cache this for direct i/o.
75 stripe_cached = lio->lis_cached_entry != LIS_CACHE_ENTRY_NONE &&
76 page->cp_type == CPT_TRANSIENT;
78 offset = cl_offset(obj, index);
81 entry = lio->lis_cached_entry;
82 stripe = lio->lis_cached_stripe;
83 /* Offset can never go backwards in an i/o, so this is valid */
84 suboff = lio->lis_cached_suboff + offset - lio->lis_cached_off;
86 entry = lov_io_layout_at(lio, offset);
90 stripe = lov_stripe_number(loo->lo_lsm, entry, offset);
91 rc = lov_stripe_offset(loo->lo_lsm, entry, offset, stripe,
94 lio->lis_cached_entry = entry;
95 lio->lis_cached_stripe = stripe;
96 lio->lis_cached_off = offset;
97 lio->lis_cached_suboff = suboff;
100 if (entry < 0 || !lsm_entry_inited(loo->lo_lsm, entry)) {
101 /* non-existing layout component */
102 lov_page_init_empty(env, obj, page, index);
106 CDEBUG(D_PAGE, "offset %llu, entry %d, stripe %d, suboff %llu\n",
107 offset, entry, stripe, suboff);
109 page->cp_lov_index = lov_comp_index(entry, stripe);
110 LASSERT(page->cp_lov_index != CP_LOV_INDEX_EMPTY);
112 if (!stripe_cached) {
113 sub = lov_sub_get(env, lio, page->cp_lov_index);
115 RETURN(PTR_ERR(sub));
117 sub = lio->lis_cached_sub;
120 lio->lis_cached_sub = sub;
122 r0 = lov_r0(loo, entry);
123 LASSERT(stripe < r0->lo_nr);
125 subobj = lovsub2cl(r0->lo_sub[stripe]);
126 cl_object_for_each(o, subobj) {
127 if (o->co_ops->coo_page_init) {
128 rc = o->co_ops->coo_page_init(sub->sub_env, o, page,
129 cl_index(subobj, suboff));
138 int lov_page_init_empty(const struct lu_env *env, struct cl_object *obj,
139 struct cl_page *page, pgoff_t index)
144 BUILD_BUG_ON(!__same_type(page->cp_lov_index, CP_LOV_INDEX_EMPTY));
145 page->cp_lov_index = CP_LOV_INDEX_EMPTY;
147 addr = kmap(page->cp_vmpage);
148 memset(addr, 0, PAGE_SIZE);
149 kunmap(page->cp_vmpage);
150 SetPageUptodate(page->cp_vmpage);
154 int lov_page_init_foreign(const struct lu_env *env, struct cl_object *obj,
155 struct cl_page *page, pgoff_t index)
157 CDEBUG(D_PAGE, DFID" has no data\n", PFID(lu_object_fid(&obj->co_lu)));