blob: f9621b0fd469ea2d9a13642eada7618d406d33f2 [file] [log] [blame]
Peng Taod7e09d02013-05-02 16:46:55 +08001/*
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
Oleg Drokin6a5b99a2016-06-14 23:33:40 -040018 * http://www.gnu.org/licenses/gpl-2.0.html
Peng Taod7e09d02013-05-02 16:46:55 +080019 *
Peng Taod7e09d02013-05-02 16:46:55 +080020 * 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 *
Andreas Dilger1dc563a2015-11-08 18:09:37 -050026 * Copyright (c) 2011, 2015, Intel Corporation.
Peng Taod7e09d02013-05-02 16:46:55 +080027 */
28/*
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
31 *
32 * Implementation of cl_object for LOV layer.
33 *
34 * Author: Nikita Danilov <nikita.danilov@sun.com>
35 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
36 */
37
38#define DEBUG_SUBSYSTEM S_LOV
39
40#include "lov_cl_internal.h"
Peng Taod7e09d02013-05-02 16:46:55 +080041
42/** \addtogroup lov
43 * @{
44 */
45
46/*****************************************************************************
47 *
48 * Layout operations.
49 *
50 */
51
52struct lov_layout_operations {
53 int (*llo_init)(const struct lu_env *env, struct lov_device *dev,
54 struct lov_object *lov,
55 const struct cl_object_conf *conf,
56 union lov_layout_state *state);
57 int (*llo_delete)(const struct lu_env *env, struct lov_object *lov,
Oleg Drokinf1564f12016-02-26 01:50:05 -050058 union lov_layout_state *state);
Peng Taod7e09d02013-05-02 16:46:55 +080059 void (*llo_fini)(const struct lu_env *env, struct lov_object *lov,
60 union lov_layout_state *state);
61 void (*llo_install)(const struct lu_env *env, struct lov_object *lov,
62 union lov_layout_state *state);
63 int (*llo_print)(const struct lu_env *env, void *cookie,
64 lu_printer_t p, const struct lu_object *o);
65 int (*llo_page_init)(const struct lu_env *env, struct cl_object *obj,
Jinshan Xiong7addf402016-03-30 19:48:32 -040066 struct cl_page *page, pgoff_t index);
Peng Taod7e09d02013-05-02 16:46:55 +080067 int (*llo_lock_init)(const struct lu_env *env,
68 struct cl_object *obj, struct cl_lock *lock,
69 const struct cl_io *io);
70 int (*llo_io_init)(const struct lu_env *env,
71 struct cl_object *obj, struct cl_io *io);
72 int (*llo_getattr)(const struct lu_env *env, struct cl_object *obj,
73 struct cl_attr *attr);
74};
75
76static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov);
77
78/*****************************************************************************
79 *
80 * Lov object layout operations.
81 *
82 */
83
84static void lov_install_empty(const struct lu_env *env,
85 struct lov_object *lov,
86 union lov_layout_state *state)
87{
88 /*
89 * File without objects.
90 */
91}
92
93static int lov_init_empty(const struct lu_env *env,
94 struct lov_device *dev, struct lov_object *lov,
95 const struct cl_object_conf *conf,
96 union lov_layout_state *state)
97{
98 return 0;
99}
100
101static void lov_install_raid0(const struct lu_env *env,
102 struct lov_object *lov,
103 union lov_layout_state *state)
104{
105}
106
107static struct cl_object *lov_sub_find(const struct lu_env *env,
108 struct cl_device *dev,
109 const struct lu_fid *fid,
110 const struct cl_object_conf *conf)
111{
112 struct lu_object *o;
113
Peng Taod7e09d02013-05-02 16:46:55 +0800114 o = lu_object_find_at(env, cl2lu_dev(dev), fid, &conf->coc_lu);
115 LASSERT(ergo(!IS_ERR(o), o->lo_dev->ld_type == &lovsub_device_type));
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800116 return lu2cl(o);
Peng Taod7e09d02013-05-02 16:46:55 +0800117}
118
119static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
Bobi Jamf34b6cd2014-02-09 02:51:45 -0500120 struct cl_object *stripe, struct lov_layout_raid0 *r0,
121 int idx)
Peng Taod7e09d02013-05-02 16:46:55 +0800122{
123 struct cl_object_header *hdr;
124 struct cl_object_header *subhdr;
125 struct cl_object_header *parent;
126 struct lov_oinfo *oinfo;
127 int result;
128
129 if (OBD_FAIL_CHECK(OBD_FAIL_LOV_INIT)) {
130 /* For sanity:test_206.
131 * Do not leave the object in cache to avoid accessing
132 * freed memory. This is because osc_object is referring to
133 * lov_oinfo of lsm_stripe_data which will be freed due to
Oleg Drokinacb9abc2016-02-24 22:00:32 -0500134 * this failure.
135 */
Peng Taod7e09d02013-05-02 16:46:55 +0800136 cl_object_kill(env, stripe);
137 cl_object_put(env, stripe);
138 return -EIO;
139 }
140
141 hdr = cl_object_header(lov2cl(lov));
142 subhdr = cl_object_header(stripe);
Peng Taod7e09d02013-05-02 16:46:55 +0800143
144 oinfo = lov->lo_lsm->lsm_oinfo[idx];
145 CDEBUG(D_INODE, DFID"@%p[%d] -> "DFID"@%p: ostid: "DOSTID
146 " idx: %d gen: %d\n",
147 PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
148 PFID(&hdr->coh_lu.loh_fid), hdr, POSTID(&oinfo->loi_oi),
149 oinfo->loi_ost_idx, oinfo->loi_ost_gen);
150
Bobi Jamf34b6cd2014-02-09 02:51:45 -0500151 /* reuse ->coh_attr_guard to protect coh_parent change */
152 spin_lock(&subhdr->coh_attr_guard);
153 parent = subhdr->coh_parent;
Oleg Drokin00697c42016-02-16 00:46:45 -0500154 if (!parent) {
Peng Taod7e09d02013-05-02 16:46:55 +0800155 subhdr->coh_parent = hdr;
Bobi Jamf34b6cd2014-02-09 02:51:45 -0500156 spin_unlock(&subhdr->coh_attr_guard);
Peng Taod7e09d02013-05-02 16:46:55 +0800157 subhdr->coh_nesting = hdr->coh_nesting + 1;
158 lu_object_ref_add(&stripe->co_lu, "lov-parent", lov);
159 r0->lo_sub[idx] = cl2lovsub(stripe);
160 r0->lo_sub[idx]->lso_super = lov;
161 r0->lo_sub[idx]->lso_index = idx;
162 result = 0;
163 } else {
164 struct lu_object *old_obj;
165 struct lov_object *old_lov;
166 unsigned int mask = D_INODE;
167
Bobi Jamf34b6cd2014-02-09 02:51:45 -0500168 spin_unlock(&subhdr->coh_attr_guard);
Peng Taod7e09d02013-05-02 16:46:55 +0800169 old_obj = lu_object_locate(&parent->coh_lu, &lov_device_type);
Oleg Drokin00697c42016-02-16 00:46:45 -0500170 LASSERT(old_obj);
Peng Taod7e09d02013-05-02 16:46:55 +0800171 old_lov = cl2lov(lu2cl(old_obj));
172 if (old_lov->lo_layout_invalid) {
173 /* the object's layout has already changed but isn't
Oleg Drokinacb9abc2016-02-24 22:00:32 -0500174 * refreshed
175 */
Peng Taod7e09d02013-05-02 16:46:55 +0800176 lu_object_unhash(env, &stripe->co_lu);
177 result = -EAGAIN;
178 } else {
179 mask = D_ERROR;
180 result = -EIO;
181 }
182
183 LU_OBJECT_DEBUG(mask, env, &stripe->co_lu,
Alex Zhuravleve93876d2016-06-20 16:55:36 -0400184 "stripe %d is already owned.", idx);
185 LU_OBJECT_DEBUG(mask, env, old_obj, "owned.");
Peng Taod7e09d02013-05-02 16:46:55 +0800186 LU_OBJECT_HEADER(mask, env, lov2lu(lov), "try to own.\n");
187 cl_object_put(env, stripe);
188 }
189 return result;
190}
191
Jinshan Xiong7addf402016-03-30 19:48:32 -0400192static int lov_page_slice_fixup(struct lov_object *lov,
193 struct cl_object *stripe)
194{
195 struct cl_object_header *hdr = cl_object_header(&lov->lo_cl);
196 struct cl_object *o;
197
198 cl_object_for_each(o, stripe)
199 o->co_slice_off += hdr->coh_page_bufsize;
200
201 return cl_object_header(stripe)->coh_page_bufsize;
202}
203
Peng Taod7e09d02013-05-02 16:46:55 +0800204static int lov_init_raid0(const struct lu_env *env,
205 struct lov_device *dev, struct lov_object *lov,
206 const struct cl_object_conf *conf,
207 union lov_layout_state *state)
208{
209 int result;
210 int i;
211
212 struct cl_object *stripe;
213 struct lov_thread_info *lti = lov_env_info(env);
214 struct cl_object_conf *subconf = &lti->lti_stripe_conf;
215 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
216 struct lu_fid *ofid = &lti->lti_fid;
217 struct lov_layout_raid0 *r0 = &state->raid0;
218
Peng Taod7e09d02013-05-02 16:46:55 +0800219 if (lsm->lsm_magic != LOV_MAGIC_V1 && lsm->lsm_magic != LOV_MAGIC_V3) {
220 dump_lsm(D_ERROR, lsm);
221 LASSERTF(0, "magic mismatch, expected %d/%d, actual %d.\n",
222 LOV_MAGIC_V1, LOV_MAGIC_V3, lsm->lsm_magic);
223 }
224
Oleg Drokin00697c42016-02-16 00:46:45 -0500225 LASSERT(!lov->lo_lsm);
Peng Taod7e09d02013-05-02 16:46:55 +0800226 lov->lo_lsm = lsm_addref(lsm);
227 r0->lo_nr = lsm->lsm_stripe_count;
228 LASSERT(r0->lo_nr <= lov_targets_nr(dev));
229
Julia Lawall3d0ba712015-06-11 14:02:54 +0200230 r0->lo_sub = libcfs_kvzalloc(r0->lo_nr * sizeof(r0->lo_sub[0]),
231 GFP_NOFS);
Oleg Drokin00697c42016-02-16 00:46:45 -0500232 if (r0->lo_sub) {
Jinshan Xiong7addf402016-03-30 19:48:32 -0400233 int psz = 0;
234
Peng Taod7e09d02013-05-02 16:46:55 +0800235 result = 0;
236 subconf->coc_inode = conf->coc_inode;
237 spin_lock_init(&r0->lo_sub_lock);
238 /*
239 * Create stripe cl_objects.
240 */
241 for (i = 0; i < r0->lo_nr && result == 0; ++i) {
242 struct cl_device *subdev;
243 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
244 int ost_idx = oinfo->loi_ost_idx;
245
Yang Sheng397632e2015-03-25 21:53:22 -0400246 if (lov_oinfo_is_dummy(oinfo))
247 continue;
248
Peng Taod7e09d02013-05-02 16:46:55 +0800249 result = ostid_to_fid(ofid, &oinfo->loi_oi,
250 oinfo->loi_ost_idx);
251 if (result != 0)
Julia Lawall18751662014-09-09 15:44:08 +0200252 goto out;
Peng Taod7e09d02013-05-02 16:46:55 +0800253
254 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
255 subconf->u.coc_oinfo = oinfo;
Oleg Drokin00697c42016-02-16 00:46:45 -0500256 LASSERTF(subdev, "not init ost %d\n", ost_idx);
Peng Taod7e09d02013-05-02 16:46:55 +0800257 /* In the function below, .hs_keycmp resolves to
Oleg Drokinacb9abc2016-02-24 22:00:32 -0500258 * lu_obj_hop_keycmp()
259 */
Peng Taod7e09d02013-05-02 16:46:55 +0800260 /* coverity[overrun-buffer-val] */
261 stripe = lov_sub_find(env, subdev, ofid, subconf);
262 if (!IS_ERR(stripe)) {
263 result = lov_init_sub(env, lov, stripe, r0, i);
264 if (result == -EAGAIN) { /* try again */
265 --i;
266 result = 0;
Jinshan Xiong7addf402016-03-30 19:48:32 -0400267 continue;
Peng Taod7e09d02013-05-02 16:46:55 +0800268 }
269 } else {
270 result = PTR_ERR(stripe);
271 }
Jinshan Xiong7addf402016-03-30 19:48:32 -0400272
273 if (result == 0) {
274 int sz = lov_page_slice_fixup(lov, stripe);
275
276 LASSERT(ergo(psz > 0, psz == sz));
277 psz = sz;
278 }
Peng Taod7e09d02013-05-02 16:46:55 +0800279 }
Jinshan Xiong7addf402016-03-30 19:48:32 -0400280 if (result == 0)
281 cl_object_header(&lov->lo_cl)->coh_page_bufsize += psz;
Oleg Drokinda5ecb42016-04-01 15:18:01 -0400282 } else {
Peng Taod7e09d02013-05-02 16:46:55 +0800283 result = -ENOMEM;
Oleg Drokinda5ecb42016-04-01 15:18:01 -0400284 }
Peng Taod7e09d02013-05-02 16:46:55 +0800285out:
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800286 return result;
Peng Taod7e09d02013-05-02 16:46:55 +0800287}
288
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800289static int lov_init_released(const struct lu_env *env,
Oleg Drokinf1564f12016-02-26 01:50:05 -0500290 struct lov_device *dev, struct lov_object *lov,
291 const struct cl_object_conf *conf,
292 union lov_layout_state *state)
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800293{
294 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
295
Oleg Drokin00697c42016-02-16 00:46:45 -0500296 LASSERT(lsm);
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800297 LASSERT(lsm_is_released(lsm));
Oleg Drokin00697c42016-02-16 00:46:45 -0500298 LASSERT(!lov->lo_lsm);
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800299
300 lov->lo_lsm = lsm_addref(lsm);
301 return 0;
302}
303
Peng Taod7e09d02013-05-02 16:46:55 +0800304static int lov_delete_empty(const struct lu_env *env, struct lov_object *lov,
305 union lov_layout_state *state)
306{
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800307 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
Peng Taod7e09d02013-05-02 16:46:55 +0800308
309 lov_layout_wait(env, lov);
Peng Taod7e09d02013-05-02 16:46:55 +0800310 return 0;
311}
312
313static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
314 struct lovsub_object *los, int idx)
315{
316 struct cl_object *sub;
317 struct lov_layout_raid0 *r0;
318 struct lu_site *site;
319 struct lu_site_bkt_data *bkt;
320 wait_queue_t *waiter;
321
322 r0 = &lov->u.raid0;
323 LASSERT(r0->lo_sub[idx] == los);
324
325 sub = lovsub2cl(los);
326 site = sub->co_lu.lo_dev->ld_site;
327 bkt = lu_site_bkt_from_fid(site, &sub->co_lu.lo_header->loh_fid);
328
329 cl_object_kill(env, sub);
330 /* release a reference to the sub-object and ... */
331 lu_object_ref_del(&sub->co_lu, "lov-parent", lov);
332 cl_object_put(env, sub);
333
334 /* ... wait until it is actually destroyed---sub-object clears its
Oleg Drokinacb9abc2016-02-24 22:00:32 -0500335 * ->lo_sub[] slot in lovsub_object_fini()
336 */
Peng Taod7e09d02013-05-02 16:46:55 +0800337 if (r0->lo_sub[idx] == los) {
338 waiter = &lov_env_info(env)->lti_waiter;
Peng Tao9e795d32014-03-18 21:05:52 +0800339 init_waitqueue_entry(waiter, current);
Peng Taod7e09d02013-05-02 16:46:55 +0800340 add_wait_queue(&bkt->lsb_marche_funebre, waiter);
341 set_current_state(TASK_UNINTERRUPTIBLE);
342 while (1) {
343 /* this wait-queue is signaled at the end of
Oleg Drokinacb9abc2016-02-24 22:00:32 -0500344 * lu_object_free().
345 */
Peng Taod7e09d02013-05-02 16:46:55 +0800346 set_current_state(TASK_UNINTERRUPTIBLE);
347 spin_lock(&r0->lo_sub_lock);
348 if (r0->lo_sub[idx] == los) {
349 spin_unlock(&r0->lo_sub_lock);
Peng Taob3669a72014-03-18 21:05:53 +0800350 schedule();
Peng Taod7e09d02013-05-02 16:46:55 +0800351 } else {
352 spin_unlock(&r0->lo_sub_lock);
353 set_current_state(TASK_RUNNING);
354 break;
355 }
356 }
357 remove_wait_queue(&bkt->lsb_marche_funebre, waiter);
358 }
Oleg Drokin00697c42016-02-16 00:46:45 -0500359 LASSERT(!r0->lo_sub[idx]);
Peng Taod7e09d02013-05-02 16:46:55 +0800360}
361
362static int lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
363 union lov_layout_state *state)
364{
365 struct lov_layout_raid0 *r0 = &state->raid0;
366 struct lov_stripe_md *lsm = lov->lo_lsm;
367 int i;
368
Peng Taod7e09d02013-05-02 16:46:55 +0800369 dump_lsm(D_INODE, lsm);
370
371 lov_layout_wait(env, lov);
Oleg Drokin00697c42016-02-16 00:46:45 -0500372 if (r0->lo_sub) {
Peng Taod7e09d02013-05-02 16:46:55 +0800373 for (i = 0; i < r0->lo_nr; ++i) {
374 struct lovsub_object *los = r0->lo_sub[i];
375
Oleg Drokin00697c42016-02-16 00:46:45 -0500376 if (los) {
Jinshan Xiong06563b52016-03-30 19:48:40 -0400377 cl_object_prune(env, &los->lso_cl);
Peng Taod7e09d02013-05-02 16:46:55 +0800378 /*
379 * If top-level object is to be evicted from
380 * the cache, so are its sub-objects.
381 */
382 lov_subobject_kill(env, lov, los, i);
383 }
384 }
385 }
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800386 return 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800387}
388
389static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
390 union lov_layout_state *state)
391{
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800392 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
Peng Taod7e09d02013-05-02 16:46:55 +0800393}
394
395static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
396 union lov_layout_state *state)
397{
398 struct lov_layout_raid0 *r0 = &state->raid0;
Peng Taod7e09d02013-05-02 16:46:55 +0800399
Oleg Drokin00697c42016-02-16 00:46:45 -0500400 if (r0->lo_sub) {
Julia Lawall3d0ba712015-06-11 14:02:54 +0200401 kvfree(r0->lo_sub);
Peng Taod7e09d02013-05-02 16:46:55 +0800402 r0->lo_sub = NULL;
403 }
404
405 dump_lsm(D_INODE, lov->lo_lsm);
406 lov_free_memmd(&lov->lo_lsm);
Peng Taod7e09d02013-05-02 16:46:55 +0800407}
408
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800409static void lov_fini_released(const struct lu_env *env, struct lov_object *lov,
Oleg Drokinf1564f12016-02-26 01:50:05 -0500410 union lov_layout_state *state)
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800411{
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800412 dump_lsm(D_INODE, lov->lo_lsm);
413 lov_free_memmd(&lov->lo_lsm);
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800414}
415
Peng Taod7e09d02013-05-02 16:46:55 +0800416static int lov_print_empty(const struct lu_env *env, void *cookie,
417 lu_printer_t p, const struct lu_object *o)
418{
419 (*p)(env, cookie, "empty %d\n", lu2lov(o)->lo_layout_invalid);
420 return 0;
421}
422
423static int lov_print_raid0(const struct lu_env *env, void *cookie,
424 lu_printer_t p, const struct lu_object *o)
425{
Jinshan Xiong48d23e62013-12-03 21:58:48 +0800426 struct lov_object *lov = lu2lov(o);
427 struct lov_layout_raid0 *r0 = lov_r0(lov);
428 struct lov_stripe_md *lsm = lov->lo_lsm;
429 int i;
Peng Taod7e09d02013-05-02 16:46:55 +0800430
Jinshan Xiong48d23e62013-12-03 21:58:48 +0800431 (*p)(env, cookie, "stripes: %d, %s, lsm{%p 0x%08X %d %u %u}:\n",
Oleg Drokinf1564f12016-02-26 01:50:05 -0500432 r0->lo_nr, lov->lo_layout_invalid ? "invalid" : "valid", lsm,
433 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
434 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
Peng Taod7e09d02013-05-02 16:46:55 +0800435 for (i = 0; i < r0->lo_nr; ++i) {
436 struct lu_object *sub;
437
Oleg Drokin00697c42016-02-16 00:46:45 -0500438 if (r0->lo_sub[i]) {
Peng Taod7e09d02013-05-02 16:46:55 +0800439 sub = lovsub2lu(r0->lo_sub[i]);
440 lu_object_print(env, cookie, p, sub);
Jinshan Xiong48d23e62013-12-03 21:58:48 +0800441 } else {
Peng Taod7e09d02013-05-02 16:46:55 +0800442 (*p)(env, cookie, "sub %d absent\n", i);
Jinshan Xiong48d23e62013-12-03 21:58:48 +0800443 }
Peng Taod7e09d02013-05-02 16:46:55 +0800444 }
445 return 0;
446}
447
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800448static int lov_print_released(const struct lu_env *env, void *cookie,
Oleg Drokinf1564f12016-02-26 01:50:05 -0500449 lu_printer_t p, const struct lu_object *o)
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800450{
Jinshan Xiong48d23e62013-12-03 21:58:48 +0800451 struct lov_object *lov = lu2lov(o);
452 struct lov_stripe_md *lsm = lov->lo_lsm;
453
454 (*p)(env, cookie,
Oleg Drokinf1564f12016-02-26 01:50:05 -0500455 "released: %s, lsm{%p 0x%08X %d %u %u}:\n",
456 lov->lo_layout_invalid ? "invalid" : "valid", lsm,
457 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
458 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800459 return 0;
460}
461
Peng Taod7e09d02013-05-02 16:46:55 +0800462/**
463 * Implements cl_object_operations::coo_attr_get() method for an object
464 * without stripes (LLT_EMPTY layout type).
465 *
466 * The only attributes this layer is authoritative in this case is
467 * cl_attr::cat_blocks---it's 0.
468 */
469static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
470 struct cl_attr *attr)
471{
472 attr->cat_blocks = 0;
473 return 0;
474}
475
476static int lov_attr_get_raid0(const struct lu_env *env, struct cl_object *obj,
477 struct cl_attr *attr)
478{
479 struct lov_object *lov = cl2lov(obj);
480 struct lov_layout_raid0 *r0 = lov_r0(lov);
481 struct cl_attr *lov_attr = &r0->lo_attr;
482 int result = 0;
483
Peng Taod7e09d02013-05-02 16:46:55 +0800484 /* this is called w/o holding type guard mutex, so it must be inside
485 * an on going IO otherwise lsm may be replaced.
486 * LU-2117: it turns out there exists one exception. For mmaped files,
487 * the lock of those files may be requested in the other file's IO
488 * context, and this function is called in ccc_lock_state(), it will
489 * hit this assertion.
490 * Anyway, it's still okay to call attr_get w/o type guard as layout
Oleg Drokinacb9abc2016-02-24 22:00:32 -0500491 * can't go if locks exist.
492 */
Peng Taod7e09d02013-05-02 16:46:55 +0800493 /* LASSERT(atomic_read(&lsm->lsm_refc) > 1); */
494
495 if (!r0->lo_attr_valid) {
496 struct lov_stripe_md *lsm = lov->lo_lsm;
497 struct ost_lvb *lvb = &lov_env_info(env)->lti_lvb;
498 __u64 kms = 0;
499
500 memset(lvb, 0, sizeof(*lvb));
501 /* XXX: timestamps can be negative by sanity:test_39m,
Oleg Drokinacb9abc2016-02-24 22:00:32 -0500502 * how can it be?
503 */
Peng Taod7e09d02013-05-02 16:46:55 +0800504 lvb->lvb_atime = LLONG_MIN;
505 lvb->lvb_ctime = LLONG_MIN;
506 lvb->lvb_mtime = LLONG_MIN;
507
508 /*
509 * XXX that should be replaced with a loop over sub-objects,
510 * doing cl_object_attr_get() on them. But for now, let's
511 * reuse old lov code.
512 */
513
514 /*
515 * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
516 * happy. It's not needed, because new code uses
517 * ->coh_attr_guard spin-lock to protect consistency of
518 * sub-object attributes.
519 */
520 lov_stripe_lock(lsm);
521 result = lov_merge_lvb_kms(lsm, lvb, &kms);
522 lov_stripe_unlock(lsm);
523 if (result == 0) {
524 cl_lvb2attr(lov_attr, lvb);
525 lov_attr->cat_kms = kms;
526 r0->lo_attr_valid = 1;
527 }
528 }
529 if (result == 0) { /* merge results */
530 attr->cat_blocks = lov_attr->cat_blocks;
531 attr->cat_size = lov_attr->cat_size;
532 attr->cat_kms = lov_attr->cat_kms;
533 if (attr->cat_atime < lov_attr->cat_atime)
534 attr->cat_atime = lov_attr->cat_atime;
535 if (attr->cat_ctime < lov_attr->cat_ctime)
536 attr->cat_ctime = lov_attr->cat_ctime;
537 if (attr->cat_mtime < lov_attr->cat_mtime)
538 attr->cat_mtime = lov_attr->cat_mtime;
539 }
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800540 return result;
Peng Taod7e09d02013-05-02 16:46:55 +0800541}
542
Tobias Klauserfcda2f52014-03-05 17:37:05 +0100543static const struct lov_layout_operations lov_dispatch[] = {
Peng Taod7e09d02013-05-02 16:46:55 +0800544 [LLT_EMPTY] = {
545 .llo_init = lov_init_empty,
546 .llo_delete = lov_delete_empty,
547 .llo_fini = lov_fini_empty,
548 .llo_install = lov_install_empty,
549 .llo_print = lov_print_empty,
550 .llo_page_init = lov_page_init_empty,
551 .llo_lock_init = lov_lock_init_empty,
552 .llo_io_init = lov_io_init_empty,
553 .llo_getattr = lov_attr_get_empty
554 },
555 [LLT_RAID0] = {
556 .llo_init = lov_init_raid0,
557 .llo_delete = lov_delete_raid0,
558 .llo_fini = lov_fini_raid0,
559 .llo_install = lov_install_raid0,
560 .llo_print = lov_print_raid0,
561 .llo_page_init = lov_page_init_raid0,
562 .llo_lock_init = lov_lock_init_raid0,
563 .llo_io_init = lov_io_init_raid0,
564 .llo_getattr = lov_attr_get_raid0
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800565 },
566 [LLT_RELEASED] = {
567 .llo_init = lov_init_released,
568 .llo_delete = lov_delete_empty,
569 .llo_fini = lov_fini_released,
570 .llo_install = lov_install_empty,
571 .llo_print = lov_print_released,
572 .llo_page_init = lov_page_init_empty,
573 .llo_lock_init = lov_lock_init_empty,
574 .llo_io_init = lov_io_init_released,
575 .llo_getattr = lov_attr_get_empty
Peng Taod7e09d02013-05-02 16:46:55 +0800576 }
577};
578
Peng Taod7e09d02013-05-02 16:46:55 +0800579/**
580 * Performs a double-dispatch based on the layout type of an object.
581 */
582#define LOV_2DISPATCH_NOLOCK(obj, op, ...) \
583({ \
584 struct lov_object *__obj = (obj); \
585 enum lov_layout_type __llt; \
586 \
587 __llt = __obj->lo_type; \
588 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
589 lov_dispatch[__llt].op(__VA_ARGS__); \
590})
591
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800592/**
593 * Return lov_layout_type associated with a given lsm
594 */
Le Tan12e397c2015-02-11 12:13:14 +0800595static enum lov_layout_type lov_type(struct lov_stripe_md *lsm)
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800596{
Oleg Drokin00697c42016-02-16 00:46:45 -0500597 if (!lsm)
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800598 return LLT_EMPTY;
599 if (lsm_is_released(lsm))
600 return LLT_RELEASED;
601 return LLT_RAID0;
602}
603
Peng Taod7e09d02013-05-02 16:46:55 +0800604static inline void lov_conf_freeze(struct lov_object *lov)
605{
606 if (lov->lo_owner != current)
607 down_read(&lov->lo_type_guard);
608}
609
610static inline void lov_conf_thaw(struct lov_object *lov)
611{
612 if (lov->lo_owner != current)
613 up_read(&lov->lo_type_guard);
614}
615
616#define LOV_2DISPATCH_MAYLOCK(obj, op, lock, ...) \
617({ \
618 struct lov_object *__obj = (obj); \
619 int __lock = !!(lock); \
620 typeof(lov_dispatch[0].op(__VA_ARGS__)) __result; \
621 \
622 if (__lock) \
623 lov_conf_freeze(__obj); \
624 __result = LOV_2DISPATCH_NOLOCK(obj, op, __VA_ARGS__); \
625 if (__lock) \
626 lov_conf_thaw(__obj); \
627 __result; \
628})
629
630/**
631 * Performs a locked double-dispatch based on the layout type of an object.
632 */
633#define LOV_2DISPATCH(obj, op, ...) \
634 LOV_2DISPATCH_MAYLOCK(obj, op, 1, __VA_ARGS__)
635
636#define LOV_2DISPATCH_VOID(obj, op, ...) \
637do { \
638 struct lov_object *__obj = (obj); \
639 enum lov_layout_type __llt; \
640 \
641 lov_conf_freeze(__obj); \
642 __llt = __obj->lo_type; \
643 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
644 lov_dispatch[__llt].op(__VA_ARGS__); \
645 lov_conf_thaw(__obj); \
646} while (0)
647
648static void lov_conf_lock(struct lov_object *lov)
649{
650 LASSERT(lov->lo_owner != current);
651 down_write(&lov->lo_type_guard);
Oleg Drokin00697c42016-02-16 00:46:45 -0500652 LASSERT(!lov->lo_owner);
Peng Taod7e09d02013-05-02 16:46:55 +0800653 lov->lo_owner = current;
654}
655
656static void lov_conf_unlock(struct lov_object *lov)
657{
658 lov->lo_owner = NULL;
659 up_write(&lov->lo_type_guard);
660}
661
662static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov)
663{
664 struct l_wait_info lwi = { 0 };
Peng Taod7e09d02013-05-02 16:46:55 +0800665
666 while (atomic_read(&lov->lo_active_ios) > 0) {
Oleg Drokinf1564f12016-02-26 01:50:05 -0500667 CDEBUG(D_INODE, "file:" DFID " wait for active IO, now: %d.\n",
668 PFID(lu_object_fid(lov2lu(lov))),
669 atomic_read(&lov->lo_active_ios));
Peng Taod7e09d02013-05-02 16:46:55 +0800670
671 l_wait_event(lov->lo_waitq,
672 atomic_read(&lov->lo_active_ios) == 0, &lwi);
673 }
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800674 return 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800675}
676
677static int lov_layout_change(const struct lu_env *unused,
678 struct lov_object *lov,
679 const struct cl_object_conf *conf)
680{
681 int result;
682 enum lov_layout_type llt = LLT_EMPTY;
683 union lov_layout_state *state = &lov->u;
684 const struct lov_layout_operations *old_ops;
685 const struct lov_layout_operations *new_ops;
686
Peng Taod7e09d02013-05-02 16:46:55 +0800687 void *cookie;
688 struct lu_env *env;
689 int refcheck;
Peng Taod7e09d02013-05-02 16:46:55 +0800690
691 LASSERT(0 <= lov->lo_type && lov->lo_type < ARRAY_SIZE(lov_dispatch));
692
Oleg Drokin00697c42016-02-16 00:46:45 -0500693 if (conf->u.coc_md)
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800694 llt = lov_type(conf->u.coc_md->lsm);
Peng Taod7e09d02013-05-02 16:46:55 +0800695 LASSERT(0 <= llt && llt < ARRAY_SIZE(lov_dispatch));
696
697 cookie = cl_env_reenter();
698 env = cl_env_get(&refcheck);
699 if (IS_ERR(env)) {
700 cl_env_reexit(cookie);
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800701 return PTR_ERR(env);
Peng Taod7e09d02013-05-02 16:46:55 +0800702 }
703
Jinshan Xiong48d23e62013-12-03 21:58:48 +0800704 CDEBUG(D_INODE, DFID" from %s to %s\n",
705 PFID(lu_object_fid(lov2lu(lov))),
706 llt2str(lov->lo_type), llt2str(llt));
707
Peng Taod7e09d02013-05-02 16:46:55 +0800708 old_ops = &lov_dispatch[lov->lo_type];
709 new_ops = &lov_dispatch[llt];
710
Jinshan Xiong06563b52016-03-30 19:48:40 -0400711 result = cl_object_prune(env, &lov->lo_cl);
712 if (result != 0)
713 goto out;
Jinshan Xiongd9d47902016-03-30 19:48:28 -0400714
Peng Taod7e09d02013-05-02 16:46:55 +0800715 result = old_ops->llo_delete(env, lov, &lov->u);
716 if (result == 0) {
717 old_ops->llo_fini(env, lov, &lov->u);
718
719 LASSERT(atomic_read(&lov->lo_active_ios) == 0);
Peng Taod7e09d02013-05-02 16:46:55 +0800720
721 lov->lo_type = LLT_EMPTY;
722 result = new_ops->llo_init(env,
723 lu2lov_dev(lov->lo_cl.co_lu.lo_dev),
724 lov, conf, state);
725 if (result == 0) {
726 new_ops->llo_install(env, lov, state);
727 lov->lo_type = llt;
728 } else {
729 new_ops->llo_delete(env, lov, state);
730 new_ops->llo_fini(env, lov, state);
731 /* this file becomes an EMPTY file. */
732 }
733 }
734
Jinshan Xiong06563b52016-03-30 19:48:40 -0400735out:
Peng Taod7e09d02013-05-02 16:46:55 +0800736 cl_env_put(env, &refcheck);
737 cl_env_reexit(cookie);
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800738 return result;
Peng Taod7e09d02013-05-02 16:46:55 +0800739}
740
741/*****************************************************************************
742 *
743 * Lov object operations.
744 *
745 */
Peng Taod7e09d02013-05-02 16:46:55 +0800746int lov_object_init(const struct lu_env *env, struct lu_object *obj,
747 const struct lu_object_conf *conf)
748{
749 struct lov_device *dev = lu2lov_dev(obj->lo_dev);
750 struct lov_object *lov = lu2lov(obj);
751 const struct cl_object_conf *cconf = lu2cl_conf(conf);
752 union lov_layout_state *set = &lov->u;
753 const struct lov_layout_operations *ops;
754 int result;
755
Peng Taod7e09d02013-05-02 16:46:55 +0800756 init_rwsem(&lov->lo_type_guard);
757 atomic_set(&lov->lo_active_ios, 0);
758 init_waitqueue_head(&lov->lo_waitq);
759
760 cl_object_page_init(lu2cl(obj), sizeof(struct lov_page));
761
762 /* no locking is necessary, as object is being created */
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800763 lov->lo_type = lov_type(cconf->u.coc_md->lsm);
Peng Taod7e09d02013-05-02 16:46:55 +0800764 ops = &lov_dispatch[lov->lo_type];
765 result = ops->llo_init(env, dev, lov, cconf, set);
766 if (result == 0)
767 ops->llo_install(env, lov, set);
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800768 return result;
Peng Taod7e09d02013-05-02 16:46:55 +0800769}
770
771static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
772 const struct cl_object_conf *conf)
773{
Jinshan Xiong5dd16412013-07-23 00:06:39 +0800774 struct lov_stripe_md *lsm = NULL;
775 struct lov_object *lov = cl2lov(obj);
776 int result = 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800777
778 lov_conf_lock(lov);
779 if (conf->coc_opc == OBJECT_CONF_INVALIDATE) {
780 lov->lo_layout_invalid = true;
Julia Lawall18751662014-09-09 15:44:08 +0200781 result = 0;
782 goto out;
Peng Taod7e09d02013-05-02 16:46:55 +0800783 }
784
785 if (conf->coc_opc == OBJECT_CONF_WAIT) {
786 if (lov->lo_layout_invalid &&
787 atomic_read(&lov->lo_active_ios) > 0) {
788 lov_conf_unlock(lov);
789 result = lov_layout_wait(env, lov);
790 lov_conf_lock(lov);
791 }
Julia Lawall18751662014-09-09 15:44:08 +0200792 goto out;
Peng Taod7e09d02013-05-02 16:46:55 +0800793 }
794
795 LASSERT(conf->coc_opc == OBJECT_CONF_SET);
796
Oleg Drokin00697c42016-02-16 00:46:45 -0500797 if (conf->u.coc_md)
Peng Taod7e09d02013-05-02 16:46:55 +0800798 lsm = conf->u.coc_md->lsm;
Oleg Drokin00697c42016-02-16 00:46:45 -0500799 if ((!lsm && !lov->lo_lsm) ||
800 ((lsm && lov->lo_lsm) &&
Jinshan Xiong48d23e62013-12-03 21:58:48 +0800801 (lov->lo_lsm->lsm_layout_gen == lsm->lsm_layout_gen) &&
802 (lov->lo_lsm->lsm_pattern == lsm->lsm_pattern))) {
Peng Taod7e09d02013-05-02 16:46:55 +0800803 /* same version of layout */
804 lov->lo_layout_invalid = false;
Julia Lawall18751662014-09-09 15:44:08 +0200805 result = 0;
806 goto out;
Peng Taod7e09d02013-05-02 16:46:55 +0800807 }
808
809 /* will change layout - check if there still exists active IO. */
810 if (atomic_read(&lov->lo_active_ios) > 0) {
811 lov->lo_layout_invalid = true;
Julia Lawall18751662014-09-09 15:44:08 +0200812 result = -EBUSY;
813 goto out;
Peng Taod7e09d02013-05-02 16:46:55 +0800814 }
815
Jinshan Xiong06563b52016-03-30 19:48:40 -0400816 result = lov_layout_change(env, lov, conf);
817 lov->lo_layout_invalid = result != 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800818
819out:
820 lov_conf_unlock(lov);
Jinshan Xiong48d23e62013-12-03 21:58:48 +0800821 CDEBUG(D_INODE, DFID" lo_layout_invalid=%d\n",
822 PFID(lu_object_fid(lov2lu(lov))), lov->lo_layout_invalid);
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800823 return result;
Peng Taod7e09d02013-05-02 16:46:55 +0800824}
825
826static void lov_object_delete(const struct lu_env *env, struct lu_object *obj)
827{
828 struct lov_object *lov = lu2lov(obj);
829
Peng Taod7e09d02013-05-02 16:46:55 +0800830 LOV_2DISPATCH_VOID(lov, llo_delete, env, lov, &lov->u);
Peng Taod7e09d02013-05-02 16:46:55 +0800831}
832
833static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
834{
835 struct lov_object *lov = lu2lov(obj);
836
Peng Taod7e09d02013-05-02 16:46:55 +0800837 LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
838 lu_object_fini(obj);
Mike Rapoport50d30362015-10-20 12:39:51 +0300839 kmem_cache_free(lov_object_kmem, lov);
Peng Taod7e09d02013-05-02 16:46:55 +0800840}
841
842static int lov_object_print(const struct lu_env *env, void *cookie,
843 lu_printer_t p, const struct lu_object *o)
844{
845 return LOV_2DISPATCH_NOLOCK(lu2lov(o), llo_print, env, cookie, p, o);
846}
847
848int lov_page_init(const struct lu_env *env, struct cl_object *obj,
Jinshan Xiong7addf402016-03-30 19:48:32 -0400849 struct cl_page *page, pgoff_t index)
Peng Taod7e09d02013-05-02 16:46:55 +0800850{
Jinshan Xiong7addf402016-03-30 19:48:32 -0400851 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_page_init, env, obj, page,
852 index);
Peng Taod7e09d02013-05-02 16:46:55 +0800853}
854
855/**
856 * Implements cl_object_operations::clo_io_init() method for lov
857 * layer. Dispatches to the appropriate layout io initialization method.
858 */
859int lov_io_init(const struct lu_env *env, struct cl_object *obj,
860 struct cl_io *io)
861{
862 CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
863 return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
864 !io->ci_ignore_layout, env, obj, io);
865}
866
867/**
868 * An implementation of cl_object_operations::clo_attr_get() method for lov
869 * layer. For raid0 layout this collects and merges attributes of all
870 * sub-objects.
871 */
872static int lov_attr_get(const struct lu_env *env, struct cl_object *obj,
873 struct cl_attr *attr)
874{
875 /* do not take lock, as this function is called under a
Oleg Drokinacb9abc2016-02-24 22:00:32 -0500876 * spin-lock. Layout is protected from changing by ongoing IO.
877 */
Peng Taod7e09d02013-05-02 16:46:55 +0800878 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_getattr, env, obj, attr);
879}
880
881static int lov_attr_set(const struct lu_env *env, struct cl_object *obj,
882 const struct cl_attr *attr, unsigned valid)
883{
884 /*
885 * No dispatch is required here, as no layout implements this.
886 */
887 return 0;
888}
889
890int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
891 struct cl_lock *lock, const struct cl_io *io)
892{
893 /* No need to lock because we've taken one refcount of layout. */
894 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_lock_init, env, obj, lock,
895 io);
896}
897
898static const struct cl_object_operations lov_ops = {
899 .coo_page_init = lov_page_init,
900 .coo_lock_init = lov_lock_init,
901 .coo_io_init = lov_io_init,
902 .coo_attr_get = lov_attr_get,
903 .coo_attr_set = lov_attr_set,
904 .coo_conf_set = lov_conf_set
905};
906
907static const struct lu_object_operations lov_lu_obj_ops = {
908 .loo_object_init = lov_object_init,
909 .loo_object_delete = lov_object_delete,
910 .loo_object_release = NULL,
911 .loo_object_free = lov_object_free,
912 .loo_object_print = lov_object_print,
913 .loo_object_invariant = NULL
914};
915
916struct lu_object *lov_object_alloc(const struct lu_env *env,
917 const struct lu_object_header *unused,
918 struct lu_device *dev)
919{
920 struct lov_object *lov;
921 struct lu_object *obj;
922
Amitoj Kaur Chawla82101322016-02-26 14:24:35 +0530923 lov = kmem_cache_zalloc(lov_object_kmem, GFP_NOFS);
Oleg Drokin00697c42016-02-16 00:46:45 -0500924 if (lov) {
Peng Taod7e09d02013-05-02 16:46:55 +0800925 obj = lov2lu(lov);
926 lu_object_init(obj, NULL, dev);
927 lov->lo_cl.co_ops = &lov_ops;
928 lov->lo_type = -1; /* invalid, to catch uninitialized type */
929 /*
930 * object io operation vector (cl_object::co_iop) is installed
931 * later in lov_object_init(), as different vectors are used
932 * for object with different layouts.
933 */
934 obj->lo_ops = &lov_lu_obj_ops;
Oleg Drokinda5ecb42016-04-01 15:18:01 -0400935 } else {
Peng Taod7e09d02013-05-02 16:46:55 +0800936 obj = NULL;
Oleg Drokinda5ecb42016-04-01 15:18:01 -0400937 }
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800938 return obj;
Peng Taod7e09d02013-05-02 16:46:55 +0800939}
940
Oleg Drokin3ddca06f2015-10-01 00:12:16 -0400941static struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
Peng Taod7e09d02013-05-02 16:46:55 +0800942{
943 struct lov_stripe_md *lsm = NULL;
944
945 lov_conf_freeze(lov);
Oleg Drokin00697c42016-02-16 00:46:45 -0500946 if (lov->lo_lsm) {
Peng Taod7e09d02013-05-02 16:46:55 +0800947 lsm = lsm_addref(lov->lo_lsm);
948 CDEBUG(D_INODE, "lsm %p addref %d/%d by %p.\n",
Oleg Drokinf1564f12016-02-26 01:50:05 -0500949 lsm, atomic_read(&lsm->lsm_refc),
950 lov->lo_layout_invalid, current);
Peng Taod7e09d02013-05-02 16:46:55 +0800951 }
952 lov_conf_thaw(lov);
953 return lsm;
954}
955
Peng Taod7e09d02013-05-02 16:46:55 +0800956struct lov_stripe_md *lov_lsm_get(struct cl_object *clobj)
957{
958 struct lu_object *luobj;
959 struct lov_stripe_md *lsm = NULL;
960
Oleg Drokin00697c42016-02-16 00:46:45 -0500961 if (!clobj)
Peng Taod7e09d02013-05-02 16:46:55 +0800962 return NULL;
963
964 luobj = lu_object_locate(&cl_object_header(clobj)->coh_lu,
965 &lov_device_type);
Oleg Drokin00697c42016-02-16 00:46:45 -0500966 if (luobj)
Peng Taod7e09d02013-05-02 16:46:55 +0800967 lsm = lov_lsm_addref(lu2lov(luobj));
968 return lsm;
969}
970EXPORT_SYMBOL(lov_lsm_get);
971
972void lov_lsm_put(struct cl_object *unused, struct lov_stripe_md *lsm)
973{
Oleg Drokin00697c42016-02-16 00:46:45 -0500974 if (lsm)
Peng Taod7e09d02013-05-02 16:46:55 +0800975 lov_free_memmd(&lsm);
976}
977EXPORT_SYMBOL(lov_lsm_put);
978
979int lov_read_and_clear_async_rc(struct cl_object *clob)
980{
981 struct lu_object *luobj;
982 int rc = 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800983
984 luobj = lu_object_locate(&cl_object_header(clob)->coh_lu,
985 &lov_device_type);
Oleg Drokin00697c42016-02-16 00:46:45 -0500986 if (luobj) {
Peng Taod7e09d02013-05-02 16:46:55 +0800987 struct lov_object *lov = lu2lov(luobj);
988
989 lov_conf_freeze(lov);
990 switch (lov->lo_type) {
991 case LLT_RAID0: {
992 struct lov_stripe_md *lsm;
993 int i;
994
995 lsm = lov->lo_lsm;
Peng Taod7e09d02013-05-02 16:46:55 +0800996 for (i = 0; i < lsm->lsm_stripe_count; i++) {
997 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
Yang Sheng397632e2015-03-25 21:53:22 -0400998
999 if (lov_oinfo_is_dummy(loi))
1000 continue;
1001
Peng Taod7e09d02013-05-02 16:46:55 +08001002 if (loi->loi_ar.ar_rc && !rc)
1003 rc = loi->loi_ar.ar_rc;
1004 loi->loi_ar.ar_rc = 0;
1005 }
1006 }
Jinshan Xiong5dd16412013-07-23 00:06:39 +08001007 case LLT_RELEASED:
Peng Taod7e09d02013-05-02 16:46:55 +08001008 case LLT_EMPTY:
1009 break;
1010 default:
1011 LBUG();
1012 }
1013 lov_conf_thaw(lov);
1014 }
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +08001015 return rc;
Peng Taod7e09d02013-05-02 16:46:55 +08001016}
1017EXPORT_SYMBOL(lov_read_and_clear_async_rc);
1018
1019/** @} lov */