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) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * Implementation of cl_page for LOV layer.
38 * Author: Nikita Danilov <nikita.danilov@sun.com>
39 * Author: Jinshan Xiong <jinshan.xiong@intel.com>
42 #define DEBUG_SUBSYSTEM S_LOV
44 #include "lov_cl_internal.h"
50 /*****************************************************************************
52 * Lov page operations.
57 * Adjust the stripe index by layout of raid0. @max_index is the maximum
58 * page index covered by an underlying DLM lock.
59 * This function converts max_index from stripe level to file level, and make
60 * sure it's not beyond one stripe.
62 static int lov_raid0_page_is_under_lock(const struct lu_env *env,
63 const struct cl_page_slice *slice,
67 struct lov_object *loo = cl2lov(slice->cpl_obj);
68 struct lov_layout_raid0 *r0 = lov_r0(loo);
69 pgoff_t index = *max_index;
70 unsigned int pps; /* pages per stripe */
73 CDEBUG(D_READA, "*max_index = %lu, nr = %d\n", index, r0->lo_nr);
74 if (index == 0) /* the page is not covered by any lock */
77 if (r0->lo_nr == 1) /* single stripe file */
80 /* max_index is stripe level, convert it into file level */
81 if (index != CL_PAGE_EOF) {
82 int stripeno = lov_page_stripe(slice->cpl_page);
83 *max_index = lov_stripe_pgoff(loo->lo_lsm, index, stripeno);
86 /* calculate the end of current stripe */
87 pps = loo->lo_lsm->lsm_stripe_size >> PAGE_CACHE_SHIFT;
88 index = ((slice->cpl_index + pps) & ~(pps - 1)) - 1;
90 /* never exceed the end of the stripe */
91 *max_index = min_t(pgoff_t, *max_index, index);
95 static int lov_raid0_page_print(const struct lu_env *env,
96 const struct cl_page_slice *slice,
97 void *cookie, lu_printer_t printer)
99 struct lov_page *lp = cl2lov_page(slice);
101 return (*printer)(env, cookie, LUSTRE_LOV_NAME"-page@%p, raid0\n", lp);
104 static const struct cl_page_operations lov_raid0_page_ops = {
105 .cpo_is_under_lock = lov_raid0_page_is_under_lock,
106 .cpo_print = lov_raid0_page_print
109 int lov_page_init_raid0(const struct lu_env *env, struct cl_object *obj,
110 struct cl_page *page, pgoff_t index)
112 struct lov_object *loo = cl2lov(obj);
113 struct lov_layout_raid0 *r0 = lov_r0(loo);
114 struct lov_io *lio = lov_env_io(env);
115 struct cl_object *subobj;
117 struct lov_io_sub *sub;
118 struct lov_page *lpg = cl_object_page_slice(obj, page);
125 offset = cl_offset(obj, index);
126 stripe = lov_stripe_number(loo->lo_lsm, offset);
127 LASSERT(stripe < r0->lo_nr);
128 rc = lov_stripe_offset(loo->lo_lsm, offset, stripe,
132 cl_page_slice_add(page, &lpg->lps_cl, obj, index, &lov_raid0_page_ops);
134 sub = lov_sub_get(env, lio, stripe);
136 RETURN(PTR_ERR(sub));
138 subobj = lovsub2cl(r0->lo_sub[stripe]);
139 cfs_list_for_each_entry(o, &subobj->co_lu.lo_header->loh_layers,
141 if (o->co_ops->coo_page_init != NULL) {
142 rc = o->co_ops->coo_page_init(sub->sub_env, o, page,
143 cl_index(subobj, suboff));
152 static int lov_empty_page_print(const struct lu_env *env,
153 const struct cl_page_slice *slice,
154 void *cookie, lu_printer_t printer)
156 struct lov_page *lp = cl2lov_page(slice);
158 return (*printer)(env, cookie, LUSTRE_LOV_NAME"-page@%p, empty.\n", lp);
161 static const struct cl_page_operations lov_empty_page_ops = {
162 .cpo_print = lov_empty_page_print
165 int lov_page_init_empty(const struct lu_env *env, struct cl_object *obj,
166 struct cl_page *page, pgoff_t index)
168 struct lov_page *lpg = cl_object_page_slice(obj, page);
172 cl_page_slice_add(page, &lpg->lps_cl, obj, index, &lov_empty_page_ops);
173 addr = kmap(page->cp_vmpage);
174 memset(addr, 0, cl_page_size(obj));
175 kunmap(page->cp_vmpage);
176 cl_page_export(env, page, 1);