Whamcloud - gitweb
LU-16118 build: Use pde_data() when available
[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                 if (entry < 0)
88                         return(-ENODATA);
89
90                 stripe = lov_stripe_number(loo->lo_lsm, entry, offset);
91                 rc = lov_stripe_offset(loo->lo_lsm, entry, offset, stripe,
92                                        &suboff);
93                 LASSERT(rc == 0);
94                 lio->lis_cached_entry = entry;
95                 lio->lis_cached_stripe = stripe;
96                 lio->lis_cached_off = offset;
97                 lio->lis_cached_suboff = suboff;
98         }
99
100         if (entry < 0 || !lsm_entry_inited(loo->lo_lsm, entry)) {
101                 /* non-existing layout component */
102                 lov_page_init_empty(env, obj, page, index);
103                 RETURN(0);
104         }
105
106         CDEBUG(D_PAGE, "offset %llu, entry %d, stripe %d, suboff %llu\n",
107                offset, entry, stripe, suboff);
108
109         page->cp_lov_index = lov_comp_index(entry, stripe);
110         LASSERT(page->cp_lov_index != CP_LOV_INDEX_EMPTY);
111
112         if (!stripe_cached) {
113                 sub = lov_sub_get(env, lio, page->cp_lov_index);
114                 if (IS_ERR(sub))
115                         RETURN(PTR_ERR(sub));
116         } else {
117                 sub = lio->lis_cached_sub;
118         }
119
120         lio->lis_cached_sub = sub;
121
122         r0 = lov_r0(loo, entry);
123         LASSERT(stripe < r0->lo_nr);
124
125         subobj = lovsub2cl(r0->lo_sub[stripe]);
126         cl_object_for_each(o, subobj) {
127                 if (o->co_ops->coo_page_init) {
128                         rc = o->co_ops->coo_page_init(sub->sub_env, o, page,
129                                                       cl_index(subobj, suboff));
130                         if (rc != 0)
131                                 break;
132                 }
133         }
134
135         RETURN(rc);
136 }
137
138 int lov_page_init_empty(const struct lu_env *env, struct cl_object *obj,
139                         struct cl_page *page, pgoff_t index)
140 {
141         void *addr;
142
143         ENTRY;
144         BUILD_BUG_ON(!__same_type(page->cp_lov_index, CP_LOV_INDEX_EMPTY));
145         page->cp_lov_index = CP_LOV_INDEX_EMPTY;
146
147         addr = kmap(page->cp_vmpage);
148         memset(addr, 0, cl_page_size(obj));
149         kunmap(page->cp_vmpage);
150         SetPageUptodate(page->cp_vmpage);
151         RETURN(0);
152 }
153
154 int lov_page_init_foreign(const struct lu_env *env, struct cl_object *obj,
155                         struct cl_page *page, pgoff_t index)
156 {
157         CDEBUG(D_PAGE, DFID" has no data\n", PFID(lu_object_fid(&obj->co_lu)));
158         RETURN(-ENODATA);
159 }
160
161 /** @} lov */