Whamcloud - gitweb
LU-8468 kernel: kernel update RHEL7.2 [3.10.0-327.28.2.el7]
[fs/lustre-release.git] / lustre / lov / lov_page.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2015, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * Implementation of cl_page for LOV layer.
37  *
38  *   Author: Nikita Danilov <nikita.danilov@sun.com>
39  *   Author: Jinshan Xiong <jinshan.xiong@intel.com>
40  */
41
42 #define DEBUG_SUBSYSTEM S_LOV
43
44 #include "lov_cl_internal.h"
45
46 /** \addtogroup lov
47  *  @{
48  */
49
50 /*****************************************************************************
51  *
52  * Lov page operations.
53  *
54  */
55
56 static int lov_raid0_page_print(const struct lu_env *env,
57                                 const struct cl_page_slice *slice,
58                                 void *cookie, lu_printer_t printer)
59 {
60         struct lov_page *lp = cl2lov_page(slice);
61
62         return (*printer)(env, cookie, LUSTRE_LOV_NAME"-page@%p, raid0\n", lp);
63 }
64
65 static const struct cl_page_operations lov_raid0_page_ops = {
66         .cpo_print = lov_raid0_page_print
67 };
68
69 int lov_page_init_raid0(const struct lu_env *env, struct cl_object *obj,
70                         struct cl_page *page, pgoff_t index)
71 {
72         struct lov_object *loo = cl2lov(obj);
73         struct lov_layout_raid0 *r0 = lov_r0(loo);
74         struct lov_io     *lio = lov_env_io(env);
75         struct cl_object  *subobj;
76         struct cl_object  *o;
77         struct lov_io_sub *sub;
78         struct lov_page   *lpg = cl_object_page_slice(obj, page);
79         loff_t             offset;
80         loff_t                   suboff;
81         int                stripe;
82         int                rc;
83         ENTRY;
84
85         offset = cl_offset(obj, index);
86         stripe = lov_stripe_number(loo->lo_lsm, offset);
87         LASSERT(stripe < r0->lo_nr);
88         rc = lov_stripe_offset(loo->lo_lsm, offset, stripe,
89                                &suboff);
90         LASSERT(rc == 0);
91
92         lpg->lps_stripe = stripe;
93         cl_page_slice_add(page, &lpg->lps_cl, obj, index, &lov_raid0_page_ops);
94
95         sub = lov_sub_get(env, lio, stripe);
96         if (IS_ERR(sub))
97                 RETURN(PTR_ERR(sub));
98
99         subobj = lovsub2cl(r0->lo_sub[stripe]);
100         list_for_each_entry(o, &subobj->co_lu.lo_header->loh_layers,
101                             co_lu.lo_linkage) {
102                 if (o->co_ops->coo_page_init != NULL) {
103                         rc = o->co_ops->coo_page_init(sub->sub_env, o, page,
104                                                       cl_index(subobj, suboff));
105                         if (rc != 0)
106                                 break;
107                 }
108         }
109
110         RETURN(rc);
111 }
112
113 static int lov_empty_page_print(const struct lu_env *env,
114                                 const struct cl_page_slice *slice,
115                                 void *cookie, lu_printer_t printer)
116 {
117         struct lov_page *lp = cl2lov_page(slice);
118
119         return (*printer)(env, cookie, LUSTRE_LOV_NAME"-page@%p, empty.\n", lp);
120 }
121
122 static const struct cl_page_operations lov_empty_page_ops = {
123         .cpo_print = lov_empty_page_print
124 };
125
126 int lov_page_init_empty(const struct lu_env *env, struct cl_object *obj,
127                         struct cl_page *page, pgoff_t index)
128 {
129         struct lov_page *lpg = cl_object_page_slice(obj, page);
130         void *addr;
131         ENTRY;
132
133         cl_page_slice_add(page, &lpg->lps_cl, obj, index, &lov_empty_page_ops);
134         addr = kmap(page->cp_vmpage);
135         memset(addr, 0, cl_page_size(obj));
136         kunmap(page->cp_vmpage);
137         cl_page_export(env, page, 1);
138         RETURN(0);
139 }
140
141
142 /** @} lov */
143