1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
30 * Use is subject to license terms.
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>
41 #define DEBUG_SUBSYSTEM S_LOV
43 #include "lov_cl_internal.h"
49 /*****************************************************************************
51 * Lov page operations.
55 static int lov_page_invariant(const struct cl_page_slice *slice)
57 const struct cl_page *page = slice->cpl_page;
58 const struct cl_page *sub = lov_sub_page(slice);
60 return ergo(sub != NULL,
61 page->cp_child == sub &&
62 sub->cp_parent == page &&
63 page->cp_state == sub->cp_state);
66 static void lov_page_fini(const struct lu_env *env,
67 struct cl_page_slice *slice)
69 struct lov_page *lp = cl2lov_page(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);
82 OBD_SLAB_FREE_PTR(lp, lov_page_kmem);
86 static int lov_page_own(const struct lu_env *env,
87 const struct cl_page_slice *slice, struct cl_io *io,
90 struct lov_io *lio = lov_env_io(env);
91 struct lov_io_sub *sub;
93 LINVRNT(lov_page_invariant(slice));
94 LINVRNT(!cl2lov_page(slice)->lps_invalid);
97 sub = lov_page_subio(env, lio, slice);
99 lov_sub_page(slice)->cp_owner = sub->sub_io;
106 static void lov_page_assume(const struct lu_env *env,
107 const struct cl_page_slice *slice, struct cl_io *io)
109 lov_page_own(env, slice, io, 0);
112 static int lov_page_print(const struct lu_env *env,
113 const struct cl_page_slice *slice,
114 void *cookie, lu_printer_t printer)
116 struct lov_page *lp = cl2lov_page(slice);
118 return (*printer)(env, cookie, LUSTRE_LOV_NAME"-page@%p\n", lp);
121 static const struct cl_page_operations lov_page_ops = {
122 .cpo_fini = lov_page_fini,
123 .cpo_own = lov_page_own,
124 .cpo_assume = lov_page_assume,
125 .cpo_print = lov_page_print
128 static void lov_empty_page_fini(const struct lu_env *env,
129 struct cl_page_slice *slice)
131 struct lov_page *lp = cl2lov_page(slice);
133 LASSERT(slice->cpl_page->cp_child == NULL);
135 OBD_SLAB_FREE_PTR(lp, lov_page_kmem);
139 struct cl_page *lov_page_init_raid0(const struct lu_env *env,
140 struct cl_object *obj, struct cl_page *page,
143 struct lov_object *loo = cl2lov(obj);
144 struct lov_io *lio = lov_env_io(env);
150 struct cl_page *subpage;
151 struct cl_object *subobj;
152 struct lov_layout_raid0 *r0 = lov_r0(loo);
153 struct lov_io_sub *sub;
157 offset = cl_offset(obj, page->cp_index);
158 stripe = lov_stripe_number(r0->lo_lsm, offset);
159 LASSERT(stripe < r0->lo_nr);
160 result = lov_stripe_offset(r0->lo_lsm, offset, stripe,
162 LASSERT(result == 0);
164 subobj = lovsub2cl(r0->lo_sub[stripe]);
165 sub = lov_sub_get(env, lio, stripe);
167 GOTO(out, result = PTR_ERR(sub));
169 subpage = cl_page_find(sub->sub_env, subobj,
170 cl_index(subobj, suboff), vmpage,
173 if (!IS_ERR(subpage)) {
174 struct lov_page *lpg;
176 OBD_SLAB_ALLOC_PTR_GFP(lpg, lov_page_kmem, CFS_ALLOC_IO);
178 cl_page_put(env, subpage);
179 GOTO(out, result = -ENOMEM);
182 if (subpage->cp_parent != NULL) {
184 * This is only possible when TRANSIENT page
185 * is being created, and CACHEABLE sub-page
186 * (attached to already existing top-page) has
187 * been found. Tell cl_page_find() to use
190 LASSERT(subpage->cp_type == CPT_CACHEABLE);
191 LASSERT(page->cp_type == CPT_TRANSIENT);
192 lpg->lps_invalid = 1;
193 cl_page_put(env, subpage);
195 * XXX This assumes that lov is in the topmost
198 result = PTR_ERR(cl_page_top(subpage));
200 lu_ref_add(&subpage->cp_reference, "lov", page);
201 subpage->cp_parent = page;
202 page->cp_child = subpage;
204 cl_page_slice_add(page, &lpg->lps_cl,
207 result = PTR_ERR(subpage);
210 RETURN(ERR_PTR(result));
214 static const struct cl_page_operations lov_empty_page_ops = {
215 .cpo_fini = lov_empty_page_fini,
216 .cpo_print = lov_page_print
219 struct cl_page *lov_page_init_empty(const struct lu_env *env,
220 struct cl_object *obj, struct cl_page *page,
223 struct lov_page *lpg;
224 int result = -ENOMEM;
227 OBD_SLAB_ALLOC_PTR_GFP(lpg, lov_page_kmem, CFS_ALLOC_IO);
230 cl_page_slice_add(page, &lpg->lps_cl,
231 obj, &lov_empty_page_ops);
232 addr = cfs_kmap(vmpage);
233 memset(addr, 0, cl_page_size(obj));
235 cl_page_export(env, page, 1);
238 RETURN(ERR_PTR(result));