Whamcloud - gitweb
LU-10994 lov: remove lov_page
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * Implementation of cl_page for LOV layer.
32  *
33  *   Author: Nikita Danilov <nikita.danilov@sun.com>
34  *   Author: Jinshan Xiong <jinshan.xiong@intel.com>
35  */
36
37 #define DEBUG_SUBSYSTEM S_LOV
38
39 #include "lov_cl_internal.h"
40 #include <linux/bug.h>
41 #include <linux/compiler.h>
42
43 /** \addtogroup lov
44  *  @{
45  */
46
47 /*****************************************************************************
48  *
49  * Lov page operations.
50  *
51  */
52 int lov_page_init_composite(const struct lu_env *env, struct cl_object *obj,
53                             struct cl_page *page, pgoff_t index)
54 {
55         struct lov_object *loo = cl2lov(obj);
56         struct lov_io *lio = lov_env_io(env);
57         struct cl_object *subobj;
58         struct cl_object *o;
59         struct lov_io_sub *sub;
60         struct lov_layout_raid0 *r0;
61         loff_t offset;
62         loff_t suboff;
63         bool stripe_cached = false;
64         int entry;
65         int stripe;
66         int rc;
67
68         ENTRY;
69
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.
74          */
75         stripe_cached = lio->lis_cached_entry != LIS_CACHE_ENTRY_NONE &&
76                         page->cp_type == CPT_TRANSIENT;
77
78         offset = cl_offset(obj, index);
79
80         if (stripe_cached) {
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;
85         } else {
86                 entry = lov_io_layout_at(lio, offset);
87
88                 stripe = lov_stripe_number(loo->lo_lsm, entry, offset);
89                 rc = lov_stripe_offset(loo->lo_lsm, entry, offset, stripe,
90                                        &suboff);
91                 LASSERT(rc == 0);
92                 lio->lis_cached_entry = entry;
93                 lio->lis_cached_stripe = stripe;
94                 lio->lis_cached_off = offset;
95                 lio->lis_cached_suboff = suboff;
96         }
97
98         if (entry < 0 || !lsm_entry_inited(loo->lo_lsm, entry)) {
99                 /* non-existing layout component */
100                 lov_page_init_empty(env, obj, page, index);
101                 RETURN(0);
102         }
103
104         CDEBUG(D_PAGE, "offset %llu, entry %d, stripe %d, suboff %llu\n",
105                offset, entry, stripe, suboff);
106
107         page->cp_lov_index = lov_comp_index(entry, stripe);
108         LASSERT(page->cp_lov_index != CP_LOV_INDEX_EMPTY);
109
110         if (!stripe_cached) {
111                 sub = lov_sub_get(env, lio, page->cp_lov_index);
112                 if (IS_ERR(sub))
113                         RETURN(PTR_ERR(sub));
114         } else {
115                 sub = lio->lis_cached_sub;
116         }
117
118         lio->lis_cached_sub = sub;
119
120         r0 = lov_r0(loo, entry);
121         LASSERT(stripe < r0->lo_nr);
122
123         subobj = lovsub2cl(r0->lo_sub[stripe]);
124         cl_object_for_each(o, subobj) {
125                 if (o->co_ops->coo_page_init) {
126                         rc = o->co_ops->coo_page_init(sub->sub_env, o, page,
127                                                       cl_index(subobj, suboff));
128                         if (rc != 0)
129                                 break;
130                 }
131         }
132
133         RETURN(rc);
134 }
135
136 int lov_page_init_empty(const struct lu_env *env, struct cl_object *obj,
137                         struct cl_page *page, pgoff_t index)
138 {
139         void *addr;
140
141         ENTRY;
142         BUILD_BUG_ON(!__same_type(page->cp_lov_index, CP_LOV_INDEX_EMPTY));
143         page->cp_lov_index = CP_LOV_INDEX_EMPTY;
144
145         addr = kmap(page->cp_vmpage);
146         memset(addr, 0, cl_page_size(obj));
147         kunmap(page->cp_vmpage);
148         cl_page_export(env, page, 1);
149         RETURN(0);
150 }
151
152 int lov_page_init_foreign(const struct lu_env *env, struct cl_object *obj,
153                         struct cl_page *page, pgoff_t index)
154 {
155         CDEBUG(D_PAGE, DFID" has no data\n", PFID(lu_object_fid(&obj->co_lu)));
156         RETURN(-ENODATA);
157 }
158
159 /** @} lov */