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.
56 static int lov_page_invariant(const struct cl_page_slice *slice)
58 const struct cl_page *page = slice->cpl_page;
59 const struct cl_page *sub = lov_sub_page(slice);
61 return ergo(sub != NULL,
62 page->cp_child == sub &&
63 sub->cp_parent == page &&
64 page->cp_state == sub->cp_state);
67 static void lov_page_fini(const struct lu_env *env,
68 struct cl_page_slice *slice)
70 struct cl_page *sub = lov_sub_page(slice);
72 LINVRNT(lov_page_invariant(slice));
76 LASSERT(sub->cp_state == CPS_FREEING);
77 lu_ref_del(&sub->cp_reference, "lov", sub->cp_parent);
78 sub->cp_parent = NULL;
79 slice->cpl_page->cp_child = NULL;
80 cl_page_put(env, sub);
85 static int lov_page_own(const struct lu_env *env,
86 const struct cl_page_slice *slice, struct cl_io *io,
89 struct lov_io *lio = lov_env_io(env);
90 struct lov_io_sub *sub;
92 LINVRNT(lov_page_invariant(slice));
93 LINVRNT(!cl2lov_page(slice)->lps_invalid);
96 sub = lov_page_subio(env, lio, slice);
98 lov_sub_page(slice)->cp_owner = sub->sub_io;
105 static void lov_page_assume(const struct lu_env *env,
106 const struct cl_page_slice *slice, struct cl_io *io)
108 lov_page_own(env, slice, io, 0);
111 static int lov_page_print(const struct lu_env *env,
112 const struct cl_page_slice *slice,
113 void *cookie, lu_printer_t printer)
115 struct lov_page *lp = cl2lov_page(slice);
117 return (*printer)(env, cookie, LUSTRE_LOV_NAME"-page@%p\n", lp);
120 static const struct cl_page_operations lov_page_ops = {
121 .cpo_fini = lov_page_fini,
122 .cpo_own = lov_page_own,
123 .cpo_assume = lov_page_assume,
124 .cpo_print = lov_page_print
127 static void lov_empty_page_fini(const struct lu_env *env,
128 struct cl_page_slice *slice)
130 LASSERT(slice->cpl_page->cp_child == NULL);
133 int lov_page_init_raid0(const struct lu_env *env, struct cl_object *obj,
134 struct cl_page *page, struct page *vmpage)
136 struct lov_object *loo = cl2lov(obj);
137 struct lov_layout_raid0 *r0 = lov_r0(loo);
138 struct lov_io *lio = lov_env_io(env);
139 struct cl_page *subpage;
140 struct cl_object *subobj;
141 struct lov_io_sub *sub;
142 struct lov_page *lpg = cl_object_page_slice(obj, page);
149 offset = cl_offset(obj, page->cp_index);
150 stripe = lov_stripe_number(loo->lo_lsm, offset);
151 LASSERT(stripe < r0->lo_nr);
152 rc = lov_stripe_offset(loo->lo_lsm, offset, stripe,
156 lpg->lps_invalid = 1;
157 cl_page_slice_add(page, &lpg->lps_cl, obj, &lov_page_ops);
159 sub = lov_sub_get(env, lio, stripe);
161 RETURN(PTR_ERR(sub));
163 subobj = lovsub2cl(r0->lo_sub[stripe]);
164 subpage = cl_page_alloc(sub->sub_env, subobj, cl_index(subobj, suboff),
165 vmpage, page->cp_type);
166 if (!IS_ERR(subpage)) {
167 subpage->cp_parent = page;
168 page->cp_child = subpage;
169 lpg->lps_invalid = 0;
171 rc = PTR_ERR(subpage);
176 static const struct cl_page_operations lov_empty_page_ops = {
177 .cpo_fini = lov_empty_page_fini,
178 .cpo_print = lov_page_print
181 int lov_page_init_empty(const struct lu_env *env, struct cl_object *obj,
182 struct cl_page *page, struct page *vmpage)
184 struct lov_page *lpg = cl_object_page_slice(obj, page);
188 cl_page_slice_add(page, &lpg->lps_cl, obj, &lov_empty_page_ops);
190 memset(addr, 0, cl_page_size(obj));
192 cl_page_export(env, page, 1);