4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * lustre/lod/lod_object.c
31 * This file contains implementations of methods for the OSD API
32 * for the Logical Object Device (LOD) layer, which provides a virtual
33 * local OSD object interface to the MDD layer, and abstracts the
34 * addressing of local (OSD) and remote (OSP) objects. The API is
35 * described in the file lustre/include/dt_object.h and in
36 * Documentation/osd-api.txt.
38 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
41 #define DEBUG_SUBSYSTEM S_MDS
43 #include <linux/random.h>
46 #include <obd_class.h>
47 #include <obd_support.h>
49 #include <lustre_fid.h>
50 #include <lustre_linkea.h>
51 #include <lustre_lmv.h>
52 #include <uapi/linux/lustre/lustre_param.h>
53 #include <lustre_swab.h>
54 #include <uapi/linux/lustre/lustre_ver.h>
55 #include <lprocfs_status.h>
56 #include <md_object.h>
58 #include "lod_internal.h"
60 static const char dot[] = ".";
61 static const char dotdot[] = "..";
64 * Implementation of dt_index_operations::dio_lookup
66 * Used with regular (non-striped) objects.
68 * \see dt_index_operations::dio_lookup() in the API description for details.
70 static int lod_lookup(const struct lu_env *env, struct dt_object *dt,
71 struct dt_rec *rec, const struct dt_key *key)
73 struct dt_object *next = dt_object_child(dt);
74 return next->do_index_ops->dio_lookup(env, next, rec, key);
78 * Implementation of dt_index_operations::dio_declare_insert.
80 * Used with regular (non-striped) objects.
82 * \see dt_index_operations::dio_declare_insert() in the API description
85 static int lod_declare_insert(const struct lu_env *env, struct dt_object *dt,
86 const struct dt_rec *rec,
87 const struct dt_key *key, struct thandle *th)
89 return lod_sub_declare_insert(env, dt_object_child(dt), rec, key, th);
93 * Implementation of dt_index_operations::dio_insert.
95 * Used with regular (non-striped) objects
97 * \see dt_index_operations::dio_insert() in the API description for details.
99 static int lod_insert(const struct lu_env *env, struct dt_object *dt,
100 const struct dt_rec *rec, const struct dt_key *key,
103 return lod_sub_insert(env, dt_object_child(dt), rec, key, th);
107 * Implementation of dt_index_operations::dio_declare_delete.
109 * Used with regular (non-striped) objects.
111 * \see dt_index_operations::dio_declare_delete() in the API description
114 static int lod_declare_delete(const struct lu_env *env, struct dt_object *dt,
115 const struct dt_key *key, struct thandle *th)
117 return lod_sub_declare_delete(env, dt_object_child(dt), key, th);
121 * Implementation of dt_index_operations::dio_delete.
123 * Used with regular (non-striped) objects.
125 * \see dt_index_operations::dio_delete() in the API description for details.
127 static int lod_delete(const struct lu_env *env, struct dt_object *dt,
128 const struct dt_key *key, struct thandle *th)
130 return lod_sub_delete(env, dt_object_child(dt), key, th);
134 * Implementation of dt_it_ops::init.
136 * Used with regular (non-striped) objects.
138 * \see dt_it_ops::init() in the API description for details.
140 static struct dt_it *lod_it_init(const struct lu_env *env,
141 struct dt_object *dt, __u32 attr)
143 struct dt_object *next = dt_object_child(dt);
144 struct lod_it *it = &lod_env_info(env)->lti_it;
145 struct dt_it *it_next;
147 it_next = next->do_index_ops->dio_it.init(env, next, attr);
151 /* currently we do not use more than one iterator per thread
152 * so we store it in thread info. if at some point we need
153 * more active iterators in a single thread, we can allocate
155 LASSERT(it->lit_obj == NULL);
157 it->lit_it = it_next;
160 return (struct dt_it *)it;
163 #define LOD_CHECK_IT(env, it) \
165 LASSERT((it)->lit_obj != NULL); \
166 LASSERT((it)->lit_it != NULL); \
170 * Implementation of dt_index_operations::dio_it.fini.
172 * Used with regular (non-striped) objects.
174 * \see dt_index_operations::dio_it.fini() in the API description for details.
176 static void lod_it_fini(const struct lu_env *env, struct dt_it *di)
178 struct lod_it *it = (struct lod_it *)di;
180 LOD_CHECK_IT(env, it);
181 it->lit_obj->do_index_ops->dio_it.fini(env, it->lit_it);
183 /* the iterator not in use any more */
189 * Implementation of dt_it_ops::get.
191 * Used with regular (non-striped) objects.
193 * \see dt_it_ops::get() in the API description for details.
195 static int lod_it_get(const struct lu_env *env, struct dt_it *di,
196 const struct dt_key *key)
198 const struct lod_it *it = (const struct lod_it *)di;
200 LOD_CHECK_IT(env, it);
201 return it->lit_obj->do_index_ops->dio_it.get(env, it->lit_it, key);
205 * Implementation of dt_it_ops::put.
207 * Used with regular (non-striped) objects.
209 * \see dt_it_ops::put() in the API description for details.
211 static void lod_it_put(const struct lu_env *env, struct dt_it *di)
213 struct lod_it *it = (struct lod_it *)di;
215 LOD_CHECK_IT(env, it);
216 return it->lit_obj->do_index_ops->dio_it.put(env, it->lit_it);
220 * Implementation of dt_it_ops::next.
222 * Used with regular (non-striped) objects
224 * \see dt_it_ops::next() in the API description for details.
226 static int lod_it_next(const struct lu_env *env, struct dt_it *di)
228 struct lod_it *it = (struct lod_it *)di;
230 LOD_CHECK_IT(env, it);
231 return it->lit_obj->do_index_ops->dio_it.next(env, it->lit_it);
235 * Implementation of dt_it_ops::key.
237 * Used with regular (non-striped) objects.
239 * \see dt_it_ops::key() in the API description for details.
241 static struct dt_key *lod_it_key(const struct lu_env *env,
242 const struct dt_it *di)
244 const struct lod_it *it = (const struct lod_it *)di;
246 LOD_CHECK_IT(env, it);
247 return it->lit_obj->do_index_ops->dio_it.key(env, it->lit_it);
251 * Implementation of dt_it_ops::key_size.
253 * Used with regular (non-striped) objects.
255 * \see dt_it_ops::key_size() in the API description for details.
257 static int lod_it_key_size(const struct lu_env *env, const struct dt_it *di)
259 struct lod_it *it = (struct lod_it *)di;
261 LOD_CHECK_IT(env, it);
262 return it->lit_obj->do_index_ops->dio_it.key_size(env, it->lit_it);
266 * Implementation of dt_it_ops::rec.
268 * Used with regular (non-striped) objects.
270 * \see dt_it_ops::rec() in the API description for details.
272 static int lod_it_rec(const struct lu_env *env, const struct dt_it *di,
273 struct dt_rec *rec, __u32 attr)
275 const struct lod_it *it = (const struct lod_it *)di;
277 LOD_CHECK_IT(env, it);
278 return it->lit_obj->do_index_ops->dio_it.rec(env, it->lit_it, rec,
283 * Implementation of dt_it_ops::rec_size.
285 * Used with regular (non-striped) objects.
287 * \see dt_it_ops::rec_size() in the API description for details.
289 static int lod_it_rec_size(const struct lu_env *env, const struct dt_it *di,
292 const struct lod_it *it = (const struct lod_it *)di;
294 LOD_CHECK_IT(env, it);
295 return it->lit_obj->do_index_ops->dio_it.rec_size(env, it->lit_it,
300 * Implementation of dt_it_ops::store.
302 * Used with regular (non-striped) objects.
304 * \see dt_it_ops::store() in the API description for details.
306 static __u64 lod_it_store(const struct lu_env *env, const struct dt_it *di)
308 const struct lod_it *it = (const struct lod_it *)di;
310 LOD_CHECK_IT(env, it);
311 return it->lit_obj->do_index_ops->dio_it.store(env, it->lit_it);
315 * Implementation of dt_it_ops::load.
317 * Used with regular (non-striped) objects.
319 * \see dt_it_ops::load() in the API description for details.
321 static int lod_it_load(const struct lu_env *env, const struct dt_it *di,
324 const struct lod_it *it = (const struct lod_it *)di;
326 LOD_CHECK_IT(env, it);
327 return it->lit_obj->do_index_ops->dio_it.load(env, it->lit_it, hash);
331 * Implementation of dt_it_ops::key_rec.
333 * Used with regular (non-striped) objects.
335 * \see dt_it_ops::rec() in the API description for details.
337 static int lod_it_key_rec(const struct lu_env *env, const struct dt_it *di,
340 const struct lod_it *it = (const struct lod_it *)di;
342 LOD_CHECK_IT(env, it);
343 return it->lit_obj->do_index_ops->dio_it.key_rec(env, it->lit_it,
347 static struct dt_index_operations lod_index_ops = {
348 .dio_lookup = lod_lookup,
349 .dio_declare_insert = lod_declare_insert,
350 .dio_insert = lod_insert,
351 .dio_declare_delete = lod_declare_delete,
352 .dio_delete = lod_delete,
360 .key_size = lod_it_key_size,
362 .rec_size = lod_it_rec_size,
363 .store = lod_it_store,
365 .key_rec = lod_it_key_rec,
370 * Implementation of dt_it_ops::init.
372 * Used with striped objects. Internally just initializes the iterator
373 * on the first stripe.
375 * \see dt_it_ops::init() in the API description for details.
377 static struct dt_it *lod_striped_it_init(const struct lu_env *env,
378 struct dt_object *dt, __u32 attr)
380 struct lod_object *lo = lod_dt_obj(dt);
381 struct dt_object *next;
382 struct lod_it *it = &lod_env_info(env)->lti_it;
383 struct dt_it *it_next;
386 LASSERT(lo->ldo_dir_stripe_count > 0);
387 next = lo->ldo_stripe[0];
388 LASSERT(next != NULL);
389 LASSERT(next->do_index_ops != NULL);
391 it_next = next->do_index_ops->dio_it.init(env, next, attr);
395 /* currently we do not use more than one iterator per thread
396 * so we store it in thread info. if at some point we need
397 * more active iterators in a single thread, we can allocate
399 LASSERT(it->lit_obj == NULL);
401 it->lit_stripe_index = 0;
403 it->lit_it = it_next;
406 return (struct dt_it *)it;
409 #define LOD_CHECK_STRIPED_IT(env, it, lo) \
411 LASSERT((it)->lit_obj != NULL); \
412 LASSERT((it)->lit_it != NULL); \
413 LASSERT((lo)->ldo_dir_stripe_count > 0); \
414 LASSERT((it)->lit_stripe_index < (lo)->ldo_dir_stripe_count); \
418 * Implementation of dt_it_ops::fini.
420 * Used with striped objects.
422 * \see dt_it_ops::fini() in the API description for details.
424 static void lod_striped_it_fini(const struct lu_env *env, struct dt_it *di)
426 struct lod_it *it = (struct lod_it *)di;
427 struct lod_object *lo = lod_dt_obj(it->lit_obj);
428 struct dt_object *next;
430 /* If lit_it == NULL, then it means the sub_it has been finished,
431 * which only happens in failure cases, see lod_striped_it_next() */
432 if (it->lit_it != NULL) {
433 LOD_CHECK_STRIPED_IT(env, it, lo);
435 next = lo->ldo_stripe[it->lit_stripe_index];
436 LASSERT(next != NULL);
437 LASSERT(next->do_index_ops != NULL);
439 next->do_index_ops->dio_it.fini(env, it->lit_it);
442 /* the iterator not in use any more */
445 it->lit_stripe_index = 0;
449 * Implementation of dt_it_ops::get.
451 * Right now it's not used widely, only to reset the iterator to the
452 * initial position. It should be possible to implement a full version
453 * which chooses a correct stripe to be able to position with any key.
455 * \see dt_it_ops::get() in the API description for details.
457 static int lod_striped_it_get(const struct lu_env *env, struct dt_it *di,
458 const struct dt_key *key)
460 const struct lod_it *it = (const struct lod_it *)di;
461 struct lod_object *lo = lod_dt_obj(it->lit_obj);
462 struct dt_object *next;
465 LOD_CHECK_STRIPED_IT(env, it, lo);
467 next = lo->ldo_stripe[it->lit_stripe_index];
468 LASSERT(next != NULL);
469 LASSERT(next->do_index_ops != NULL);
471 return next->do_index_ops->dio_it.get(env, it->lit_it, key);
475 * Implementation of dt_it_ops::put.
477 * Used with striped objects.
479 * \see dt_it_ops::put() in the API description for details.
481 static void lod_striped_it_put(const struct lu_env *env, struct dt_it *di)
483 struct lod_it *it = (struct lod_it *)di;
484 struct lod_object *lo = lod_dt_obj(it->lit_obj);
485 struct dt_object *next;
487 LOD_CHECK_STRIPED_IT(env, it, lo);
489 next = lo->ldo_stripe[it->lit_stripe_index];
490 LASSERT(next != NULL);
491 LASSERT(next->do_index_ops != NULL);
493 return next->do_index_ops->dio_it.put(env, it->lit_it);
497 * Implementation of dt_it_ops::next.
499 * Used with striped objects. When the end of the current stripe is
500 * reached, the method takes the next stripe's iterator.
502 * \see dt_it_ops::next() in the API description for details.
504 static int lod_striped_it_next(const struct lu_env *env, struct dt_it *di)
506 struct lod_it *it = (struct lod_it *)di;
507 struct lod_object *lo = lod_dt_obj(it->lit_obj);
508 struct dt_object *next;
509 struct dt_it *it_next;
513 LOD_CHECK_STRIPED_IT(env, it, lo);
515 next = lo->ldo_stripe[it->lit_stripe_index];
516 LASSERT(next != NULL);
517 LASSERT(next->do_index_ops != NULL);
519 rc = next->do_index_ops->dio_it.next(env, it->lit_it);
523 if (rc == 0 && it->lit_stripe_index == 0)
526 if (rc == 0 && it->lit_stripe_index > 0) {
527 struct lu_dirent *ent;
529 ent = (struct lu_dirent *)lod_env_info(env)->lti_key;
531 rc = next->do_index_ops->dio_it.rec(env, it->lit_it,
532 (struct dt_rec *)ent,
537 /* skip . and .. for slave stripe */
538 if ((strncmp(ent->lde_name, ".",
539 le16_to_cpu(ent->lde_namelen)) == 0 &&
540 le16_to_cpu(ent->lde_namelen) == 1) ||
541 (strncmp(ent->lde_name, "..",
542 le16_to_cpu(ent->lde_namelen)) == 0 &&
543 le16_to_cpu(ent->lde_namelen) == 2))
549 /* go to next stripe */
550 if (it->lit_stripe_index + 1 >= lo->ldo_dir_stripe_count)
553 it->lit_stripe_index++;
555 next->do_index_ops->dio_it.put(env, it->lit_it);
556 next->do_index_ops->dio_it.fini(env, it->lit_it);
559 next = lo->ldo_stripe[it->lit_stripe_index];
560 LASSERT(next != NULL);
561 rc = next->do_ops->do_index_try(env, next, &dt_directory_features);
565 LASSERT(next->do_index_ops != NULL);
567 it_next = next->do_index_ops->dio_it.init(env, next, it->lit_attr);
568 if (!IS_ERR(it_next)) {
569 it->lit_it = it_next;
572 rc = PTR_ERR(it_next);
579 * Implementation of dt_it_ops::key.
581 * Used with striped objects.
583 * \see dt_it_ops::key() in the API description for details.
585 static struct dt_key *lod_striped_it_key(const struct lu_env *env,
586 const struct dt_it *di)
588 const struct lod_it *it = (const struct lod_it *)di;
589 struct lod_object *lo = lod_dt_obj(it->lit_obj);
590 struct dt_object *next;
592 LOD_CHECK_STRIPED_IT(env, it, lo);
594 next = lo->ldo_stripe[it->lit_stripe_index];
595 LASSERT(next != NULL);
596 LASSERT(next->do_index_ops != NULL);
598 return next->do_index_ops->dio_it.key(env, it->lit_it);
602 * Implementation of dt_it_ops::key_size.
604 * Used with striped objects.
606 * \see dt_it_ops::size() in the API description for details.
608 static int lod_striped_it_key_size(const struct lu_env *env,
609 const struct dt_it *di)
611 struct lod_it *it = (struct lod_it *)di;
612 struct lod_object *lo = lod_dt_obj(it->lit_obj);
613 struct dt_object *next;
615 LOD_CHECK_STRIPED_IT(env, it, lo);
617 next = lo->ldo_stripe[it->lit_stripe_index];
618 LASSERT(next != NULL);
619 LASSERT(next->do_index_ops != NULL);
621 return next->do_index_ops->dio_it.key_size(env, it->lit_it);
625 * Implementation of dt_it_ops::rec.
627 * Used with striped objects.
629 * \see dt_it_ops::rec() in the API description for details.
631 static int lod_striped_it_rec(const struct lu_env *env, const struct dt_it *di,
632 struct dt_rec *rec, __u32 attr)
634 const struct lod_it *it = (const struct lod_it *)di;
635 struct lod_object *lo = lod_dt_obj(it->lit_obj);
636 struct dt_object *next;
638 LOD_CHECK_STRIPED_IT(env, it, lo);
640 next = lo->ldo_stripe[it->lit_stripe_index];
641 LASSERT(next != NULL);
642 LASSERT(next->do_index_ops != NULL);
644 return next->do_index_ops->dio_it.rec(env, it->lit_it, rec, attr);
648 * Implementation of dt_it_ops::rec_size.
650 * Used with striped objects.
652 * \see dt_it_ops::rec_size() in the API description for details.
654 static int lod_striped_it_rec_size(const struct lu_env *env,
655 const struct dt_it *di, __u32 attr)
657 struct lod_it *it = (struct lod_it *)di;
658 struct lod_object *lo = lod_dt_obj(it->lit_obj);
659 struct dt_object *next;
661 LOD_CHECK_STRIPED_IT(env, it, lo);
663 next = lo->ldo_stripe[it->lit_stripe_index];
664 LASSERT(next != NULL);
665 LASSERT(next->do_index_ops != NULL);
667 return next->do_index_ops->dio_it.rec_size(env, it->lit_it, attr);
671 * Implementation of dt_it_ops::store.
673 * Used with striped objects.
675 * \see dt_it_ops::store() in the API description for details.
677 static __u64 lod_striped_it_store(const struct lu_env *env,
678 const struct dt_it *di)
680 const struct lod_it *it = (const struct lod_it *)di;
681 struct lod_object *lo = lod_dt_obj(it->lit_obj);
682 struct dt_object *next;
684 LOD_CHECK_STRIPED_IT(env, it, lo);
686 next = lo->ldo_stripe[it->lit_stripe_index];
687 LASSERT(next != NULL);
688 LASSERT(next->do_index_ops != NULL);
690 return next->do_index_ops->dio_it.store(env, it->lit_it);
694 * Implementation of dt_it_ops::load.
696 * Used with striped objects.
698 * \see dt_it_ops::load() in the API description for details.
700 static int lod_striped_it_load(const struct lu_env *env,
701 const struct dt_it *di, __u64 hash)
703 const struct lod_it *it = (const struct lod_it *)di;
704 struct lod_object *lo = lod_dt_obj(it->lit_obj);
705 struct dt_object *next;
707 LOD_CHECK_STRIPED_IT(env, it, lo);
709 next = lo->ldo_stripe[it->lit_stripe_index];
710 LASSERT(next != NULL);
711 LASSERT(next->do_index_ops != NULL);
713 return next->do_index_ops->dio_it.load(env, it->lit_it, hash);
716 static struct dt_index_operations lod_striped_index_ops = {
717 .dio_lookup = lod_lookup,
718 .dio_declare_insert = lod_declare_insert,
719 .dio_insert = lod_insert,
720 .dio_declare_delete = lod_declare_delete,
721 .dio_delete = lod_delete,
723 .init = lod_striped_it_init,
724 .fini = lod_striped_it_fini,
725 .get = lod_striped_it_get,
726 .put = lod_striped_it_put,
727 .next = lod_striped_it_next,
728 .key = lod_striped_it_key,
729 .key_size = lod_striped_it_key_size,
730 .rec = lod_striped_it_rec,
731 .rec_size = lod_striped_it_rec_size,
732 .store = lod_striped_it_store,
733 .load = lod_striped_it_load,
738 * Append the FID for each shard of the striped directory after the
739 * given LMV EA header.
741 * To simplify striped directory and the consistency verification,
742 * we only store the LMV EA header on disk, for both master object
743 * and slave objects. When someone wants to know the whole LMV EA,
744 * such as client readdir(), we can build the entrie LMV EA on the
745 * MDT side (in RAM) via iterating the sub-directory entries that
746 * are contained in the master object of the stripe directory.
748 * For the master object of the striped directroy, the valid name
749 * for each shard is composed of the ${shard_FID}:${shard_idx}.
751 * There may be holes in the LMV EA if some shards' name entries
752 * are corrupted or lost.
754 * \param[in] env pointer to the thread context
755 * \param[in] lo pointer to the master object of the striped directory
756 * \param[in] buf pointer to the lu_buf which will hold the LMV EA
757 * \param[in] resize whether re-allocate the buffer if it is not big enough
759 * \retval positive size of the LMV EA
760 * \retval 0 for nothing to be loaded
761 * \retval negative error number on failure
763 int lod_load_lmv_shards(const struct lu_env *env, struct lod_object *lo,
764 struct lu_buf *buf, bool resize)
766 struct lu_dirent *ent =
767 (struct lu_dirent *)lod_env_info(env)->lti_key;
768 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
769 struct dt_object *obj = dt_object_child(&lo->ldo_obj);
770 struct lmv_mds_md_v1 *lmv1 = buf->lb_buf;
772 const struct dt_it_ops *iops;
774 __u32 magic = le32_to_cpu(lmv1->lmv_magic);
779 if (magic != LMV_MAGIC_V1)
782 stripes = le32_to_cpu(lmv1->lmv_stripe_count);
786 rc = lmv_mds_md_size(stripes, magic);
790 if (buf->lb_len < lmv1_size) {
799 lu_buf_alloc(buf, lmv1_size);
804 memcpy(buf->lb_buf, tbuf.lb_buf, tbuf.lb_len);
807 if (unlikely(!dt_try_as_dir(env, obj)))
810 memset(&lmv1->lmv_stripe_fids[0], 0, stripes * sizeof(struct lu_fid));
811 iops = &obj->do_index_ops->dio_it;
812 it = iops->init(env, obj, LUDA_64BITHASH);
816 rc = iops->load(env, it, 0);
818 rc = iops->next(env, it);
823 char name[FID_LEN + 2] = "";
828 rc = iops->rec(env, it, (struct dt_rec *)ent, LUDA_64BITHASH);
834 fid_le_to_cpu(&fid, &ent->lde_fid);
835 ent->lde_namelen = le16_to_cpu(ent->lde_namelen);
836 if (ent->lde_name[0] == '.') {
837 if (ent->lde_namelen == 1)
840 if (ent->lde_namelen == 2 && ent->lde_name[1] == '.')
844 len = snprintf(name, sizeof(name),
845 DFID":", PFID(&ent->lde_fid));
846 /* The ent->lde_name is composed of ${FID}:${index} */
847 if (ent->lde_namelen < len + 1 ||
848 memcmp(ent->lde_name, name, len) != 0) {
849 CDEBUG(lod->lod_lmv_failout ? D_ERROR : D_INFO,
850 "%s: invalid shard name %.*s with the FID "DFID
851 " for the striped directory "DFID", %s\n",
852 lod2obd(lod)->obd_name, ent->lde_namelen,
853 ent->lde_name, PFID(&fid),
854 PFID(lu_object_fid(&obj->do_lu)),
855 lod->lod_lmv_failout ? "failout" : "skip");
857 if (lod->lod_lmv_failout)
865 if (ent->lde_name[len] < '0' ||
866 ent->lde_name[len] > '9') {
867 CDEBUG(lod->lod_lmv_failout ? D_ERROR : D_INFO,
868 "%s: invalid shard name %.*s with the "
869 "FID "DFID" for the striped directory "
871 lod2obd(lod)->obd_name, ent->lde_namelen,
872 ent->lde_name, PFID(&fid),
873 PFID(lu_object_fid(&obj->do_lu)),
874 lod->lod_lmv_failout ?
877 if (lod->lod_lmv_failout)
883 index = index * 10 + ent->lde_name[len++] - '0';
884 } while (len < ent->lde_namelen);
886 if (len == ent->lde_namelen) {
887 /* Out of LMV EA range. */
888 if (index >= stripes) {
889 CERROR("%s: the shard %.*s for the striped "
890 "directory "DFID" is out of the known "
891 "LMV EA range [0 - %u], failout\n",
892 lod2obd(lod)->obd_name, ent->lde_namelen,
894 PFID(lu_object_fid(&obj->do_lu)),
900 /* The slot has been occupied. */
901 if (!fid_is_zero(&lmv1->lmv_stripe_fids[index])) {
905 &lmv1->lmv_stripe_fids[index]);
906 CERROR("%s: both the shard "DFID" and "DFID
907 " for the striped directory "DFID
908 " claim the same LMV EA slot at the "
909 "index %d, failout\n",
910 lod2obd(lod)->obd_name,
911 PFID(&fid0), PFID(&fid),
912 PFID(lu_object_fid(&obj->do_lu)), index);
917 /* stored as LE mode */
918 lmv1->lmv_stripe_fids[index] = ent->lde_fid;
921 rc = iops->next(env, it);
928 RETURN(rc > 0 ? lmv_mds_md_size(stripes, magic) : rc);
932 * Implementation of dt_object_operations::do_index_try.
934 * \see dt_object_operations::do_index_try() in the API description for details.
936 static int lod_index_try(const struct lu_env *env, struct dt_object *dt,
937 const struct dt_index_features *feat)
939 struct lod_object *lo = lod_dt_obj(dt);
940 struct dt_object *next = dt_object_child(dt);
944 LASSERT(next->do_ops);
945 LASSERT(next->do_ops->do_index_try);
947 rc = lod_striping_load(env, lo);
951 rc = next->do_ops->do_index_try(env, next, feat);
955 if (lo->ldo_dir_stripe_count > 0) {
958 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
959 if (dt_object_exists(lo->ldo_stripe[i]) == 0)
961 rc = lo->ldo_stripe[i]->do_ops->do_index_try(env,
962 lo->ldo_stripe[i], feat);
966 dt->do_index_ops = &lod_striped_index_ops;
968 dt->do_index_ops = &lod_index_ops;
975 * Implementation of dt_object_operations::do_read_lock.
977 * \see dt_object_operations::do_read_lock() in the API description for details.
979 static void lod_read_lock(const struct lu_env *env, struct dt_object *dt,
982 dt_read_lock(env, dt_object_child(dt), role);
986 * Implementation of dt_object_operations::do_write_lock.
988 * \see dt_object_operations::do_write_lock() in the API description for
991 static void lod_write_lock(const struct lu_env *env, struct dt_object *dt,
994 dt_write_lock(env, dt_object_child(dt), role);
998 * Implementation of dt_object_operations::do_read_unlock.
1000 * \see dt_object_operations::do_read_unlock() in the API description for
1003 static void lod_read_unlock(const struct lu_env *env, struct dt_object *dt)
1005 dt_read_unlock(env, dt_object_child(dt));
1009 * Implementation of dt_object_operations::do_write_unlock.
1011 * \see dt_object_operations::do_write_unlock() in the API description for
1014 static void lod_write_unlock(const struct lu_env *env, struct dt_object *dt)
1016 dt_write_unlock(env, dt_object_child(dt));
1020 * Implementation of dt_object_operations::do_write_locked.
1022 * \see dt_object_operations::do_write_locked() in the API description for
1025 static int lod_write_locked(const struct lu_env *env, struct dt_object *dt)
1027 return dt_write_locked(env, dt_object_child(dt));
1031 * Implementation of dt_object_operations::do_attr_get.
1033 * \see dt_object_operations::do_attr_get() in the API description for details.
1035 static int lod_attr_get(const struct lu_env *env,
1036 struct dt_object *dt,
1037 struct lu_attr *attr)
1039 /* Note: for striped directory, client will merge attributes
1040 * from all of the sub-stripes see lmv_merge_attr(), and there
1041 * no MDD logic depend on directory nlink/size/time, so we can
1042 * always use master inode nlink and size for now. */
1043 return dt_attr_get(env, dt_object_child(dt), attr);
1046 static inline void lod_adjust_stripe_info(struct lod_layout_component *comp,
1047 struct lov_desc *desc)
1049 if (comp->llc_pattern != LOV_PATTERN_MDT) {
1050 if (!comp->llc_stripe_count)
1051 comp->llc_stripe_count =
1052 desc->ld_default_stripe_count;
1054 if (comp->llc_stripe_size <= 0)
1055 comp->llc_stripe_size = desc->ld_default_stripe_size;
1058 int lod_obj_for_each_stripe(const struct lu_env *env, struct lod_object *lo,
1060 struct lod_obj_stripe_cb_data *data)
1062 struct lod_layout_component *lod_comp;
1066 LASSERT(lo->ldo_comp_cnt != 0 && lo->ldo_comp_entries != NULL);
1067 for (i = 0; i < lo->ldo_comp_cnt; i++) {
1068 lod_comp = &lo->ldo_comp_entries[i];
1070 if (lod_comp->llc_stripe == NULL)
1073 /* has stripe but not inited yet, this component has been
1074 * declared to be created, but hasn't created yet.
1076 if (!lod_comp_inited(lod_comp))
1079 if (data->locd_comp_skip_cb &&
1080 data->locd_comp_skip_cb(env, lo, i, data))
1083 if (data->locd_comp_cb) {
1084 rc = data->locd_comp_cb(env, lo, i, data);
1089 /* could used just to do sth about component, not each
1092 if (!data->locd_stripe_cb)
1095 LASSERT(lod_comp->llc_stripe_count > 0);
1096 for (j = 0; j < lod_comp->llc_stripe_count; j++) {
1097 struct dt_object *dt = lod_comp->llc_stripe[j];
1101 rc = data->locd_stripe_cb(env, lo, dt, th, i, j, data);
1109 static bool lod_obj_attr_set_comp_skip_cb(const struct lu_env *env,
1110 struct lod_object *lo, int comp_idx,
1111 struct lod_obj_stripe_cb_data *data)
1113 struct lod_layout_component *lod_comp = &lo->ldo_comp_entries[comp_idx];
1114 bool skipped = false;
1116 if (!(data->locd_attr->la_valid & LA_LAYOUT_VERSION))
1119 switch (lo->ldo_flr_state) {
1120 case LCM_FL_WRITE_PENDING: {
1123 /* skip stale components */
1124 if (lod_comp->llc_flags & LCME_FL_STALE) {
1129 /* skip valid and overlapping components, therefore any
1130 * attempts to write overlapped components will never succeed
1131 * because client will get EINPROGRESS. */
1132 for (i = 0; i < lo->ldo_comp_cnt; i++) {
1136 if (lo->ldo_comp_entries[i].llc_flags & LCME_FL_STALE)
1139 if (lu_extent_is_overlapped(&lod_comp->llc_extent,
1140 &lo->ldo_comp_entries[i].llc_extent)) {
1148 LASSERTF(0, "impossible: %d\n", lo->ldo_flr_state);
1149 case LCM_FL_SYNC_PENDING:
1153 CDEBUG(D_LAYOUT, DFID": %s to set component %x to version: %u\n",
1154 PFID(lu_object_fid(&lo->ldo_obj.do_lu)),
1155 skipped ? "skipped" : "chose", lod_comp->llc_id,
1156 data->locd_attr->la_layout_version);
1162 lod_obj_stripe_attr_set_cb(const struct lu_env *env, struct lod_object *lo,
1163 struct dt_object *dt, struct thandle *th,
1164 int comp_idx, int stripe_idx,
1165 struct lod_obj_stripe_cb_data *data)
1167 if (data->locd_declare)
1168 return lod_sub_declare_attr_set(env, dt, data->locd_attr, th);
1170 if (data->locd_attr->la_valid & LA_LAYOUT_VERSION) {
1171 CDEBUG(D_LAYOUT, DFID": set layout version: %u, comp_idx: %d\n",
1172 PFID(lu_object_fid(&dt->do_lu)),
1173 data->locd_attr->la_layout_version, comp_idx);
1176 return lod_sub_attr_set(env, dt, data->locd_attr, th);
1180 * Implementation of dt_object_operations::do_declare_attr_set.
1182 * If the object is striped, then apply the changes to all the stripes.
1184 * \see dt_object_operations::do_declare_attr_set() in the API description
1187 static int lod_declare_attr_set(const struct lu_env *env,
1188 struct dt_object *dt,
1189 const struct lu_attr *attr,
1192 struct dt_object *next = dt_object_child(dt);
1193 struct lod_object *lo = lod_dt_obj(dt);
1198 * declare setattr on the local object
1200 rc = lod_sub_declare_attr_set(env, next, attr, th);
1204 /* osp_declare_attr_set() ignores all attributes other than
1205 * UID, GID, PROJID, and size, and osp_attr_set() ignores all
1206 * but UID, GID and PROJID. Declaration of size attr setting
1207 * happens through lod_declare_init_size(), and not through
1208 * this function. Therefore we need not load striping unless
1209 * ownership is changing. This should save memory and (we hope)
1210 * speed up rename().
1212 if (!S_ISDIR(dt->do_lu.lo_header->loh_attr)) {
1213 if (!(attr->la_valid & LA_REMOTE_ATTR_SET))
1216 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_OWNER))
1219 if (!(attr->la_valid & (LA_UID | LA_GID | LA_PROJID | LA_MODE |
1220 LA_ATIME | LA_MTIME | LA_CTIME |
1225 * load striping information, notice we don't do this when object
1226 * is being initialized as we don't need this information till
1227 * few specific cases like destroy, chown
1229 rc = lod_striping_load(env, lo);
1233 if (!lod_obj_is_striped(dt))
1237 * if object is striped declare changes on the stripes
1239 if (S_ISDIR(dt->do_lu.lo_header->loh_attr)) {
1240 LASSERT(lo->ldo_stripe);
1241 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
1242 if (lo->ldo_stripe[i] == NULL)
1244 rc = lod_sub_declare_attr_set(env, lo->ldo_stripe[i],
1250 struct lod_obj_stripe_cb_data data = { { 0 } };
1252 data.locd_attr = attr;
1253 data.locd_declare = true;
1254 data.locd_stripe_cb = lod_obj_stripe_attr_set_cb;
1255 rc = lod_obj_for_each_stripe(env, lo, th, &data);
1261 if (!dt_object_exists(next) || dt_object_remote(next) ||
1262 !S_ISREG(attr->la_mode))
1265 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_STRIPE)) {
1266 rc = lod_sub_declare_xattr_del(env, next, XATTR_NAME_LOV, th);
1270 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_CHANGE_STRIPE) ||
1271 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PFL_RANGE)) {
1272 struct lod_thread_info *info = lod_env_info(env);
1273 struct lu_buf *buf = &info->lti_buf;
1275 buf->lb_buf = info->lti_ea_store;
1276 buf->lb_len = info->lti_ea_store_size;
1277 rc = lod_sub_declare_xattr_set(env, next, buf, XATTR_NAME_LOV,
1278 LU_XATTR_REPLACE, th);
1285 * Implementation of dt_object_operations::do_attr_set.
1287 * If the object is striped, then apply the changes to all or subset of
1288 * the stripes depending on the object type and specific attributes.
1290 * \see dt_object_operations::do_attr_set() in the API description for details.
1292 static int lod_attr_set(const struct lu_env *env,
1293 struct dt_object *dt,
1294 const struct lu_attr *attr,
1297 struct dt_object *next = dt_object_child(dt);
1298 struct lod_object *lo = lod_dt_obj(dt);
1303 * apply changes to the local object
1305 rc = lod_sub_attr_set(env, next, attr, th);
1309 if (!S_ISDIR(dt->do_lu.lo_header->loh_attr)) {
1310 if (!(attr->la_valid & LA_REMOTE_ATTR_SET))
1313 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_OWNER))
1316 if (!(attr->la_valid & (LA_UID | LA_GID | LA_MODE | LA_PROJID |
1317 LA_ATIME | LA_MTIME | LA_CTIME |
1322 /* FIXME: a tricky case in the code path of mdd_layout_change():
1323 * the in-memory striping information has been freed in lod_xattr_set()
1324 * due to layout change. It has to load stripe here again. It only
1325 * changes flags of layout so declare_attr_set() is still accurate */
1326 rc = lod_striping_load(env, lo);
1330 if (!lod_obj_is_striped(dt))
1334 * if object is striped, apply changes to all the stripes
1336 if (S_ISDIR(dt->do_lu.lo_header->loh_attr)) {
1337 LASSERT(lo->ldo_stripe);
1338 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
1339 if (unlikely(lo->ldo_stripe[i] == NULL))
1342 if ((dt_object_exists(lo->ldo_stripe[i]) == 0))
1345 rc = lod_sub_attr_set(env, lo->ldo_stripe[i], attr, th);
1350 struct lod_obj_stripe_cb_data data = { { 0 } };
1352 data.locd_attr = attr;
1353 data.locd_declare = false;
1354 data.locd_comp_skip_cb = lod_obj_attr_set_comp_skip_cb;
1355 data.locd_stripe_cb = lod_obj_stripe_attr_set_cb;
1356 rc = lod_obj_for_each_stripe(env, lo, th, &data);
1362 if (!dt_object_exists(next) || dt_object_remote(next) ||
1363 !S_ISREG(attr->la_mode))
1366 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_STRIPE)) {
1367 rc = lod_sub_xattr_del(env, next, XATTR_NAME_LOV, th);
1371 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_CHANGE_STRIPE)) {
1372 struct lod_thread_info *info = lod_env_info(env);
1373 struct lu_buf *buf = &info->lti_buf;
1374 struct ost_id *oi = &info->lti_ostid;
1375 struct lu_fid *fid = &info->lti_fid;
1376 struct lov_mds_md_v1 *lmm;
1377 struct lov_ost_data_v1 *objs;
1380 rc = lod_get_lov_ea(env, lo);
1384 buf->lb_buf = info->lti_ea_store;
1385 buf->lb_len = info->lti_ea_store_size;
1386 lmm = info->lti_ea_store;
1387 magic = le32_to_cpu(lmm->lmm_magic);
1388 if (magic == LOV_MAGIC_COMP_V1) {
1389 struct lov_comp_md_v1 *lcm = buf->lb_buf;
1390 struct lov_comp_md_entry_v1 *lcme =
1391 &lcm->lcm_entries[0];
1393 lmm = buf->lb_buf + le32_to_cpu(lcme->lcme_offset);
1394 magic = le32_to_cpu(lmm->lmm_magic);
1397 if (magic == LOV_MAGIC_V1)
1398 objs = &(lmm->lmm_objects[0]);
1400 objs = &((struct lov_mds_md_v3 *)lmm)->lmm_objects[0];
1401 ostid_le_to_cpu(&objs->l_ost_oi, oi);
1402 ostid_to_fid(fid, oi, le32_to_cpu(objs->l_ost_idx));
1404 fid_to_ostid(fid, oi);
1405 ostid_cpu_to_le(oi, &objs->l_ost_oi);
1407 rc = lod_sub_xattr_set(env, next, buf, XATTR_NAME_LOV,
1408 LU_XATTR_REPLACE, th);
1409 } else if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PFL_RANGE)) {
1410 struct lod_thread_info *info = lod_env_info(env);
1411 struct lu_buf *buf = &info->lti_buf;
1412 struct lov_comp_md_v1 *lcm;
1413 struct lov_comp_md_entry_v1 *lcme;
1415 rc = lod_get_lov_ea(env, lo);
1419 buf->lb_buf = info->lti_ea_store;
1420 buf->lb_len = info->lti_ea_store_size;
1422 if (le32_to_cpu(lcm->lcm_magic) != LOV_MAGIC_COMP_V1)
1425 le32_add_cpu(&lcm->lcm_layout_gen, 1);
1426 lcme = &lcm->lcm_entries[0];
1427 le64_add_cpu(&lcme->lcme_extent.e_start, 1);
1428 le64_add_cpu(&lcme->lcme_extent.e_end, -1);
1430 rc = lod_sub_xattr_set(env, next, buf, XATTR_NAME_LOV,
1431 LU_XATTR_REPLACE, th);
1438 * Implementation of dt_object_operations::do_xattr_get.
1440 * If LOV EA is requested from the root object and it's not
1441 * found, then return default striping for the filesystem.
1443 * \see dt_object_operations::do_xattr_get() in the API description for details.
1445 static int lod_xattr_get(const struct lu_env *env, struct dt_object *dt,
1446 struct lu_buf *buf, const char *name)
1448 struct lod_thread_info *info = lod_env_info(env);
1449 struct lod_device *dev = lu2lod_dev(dt->do_lu.lo_dev);
1454 rc = dt_xattr_get(env, dt_object_child(dt), buf, name);
1455 if (strcmp(name, XATTR_NAME_LMV) == 0) {
1456 struct lmv_mds_md_v1 *lmv1;
1459 if (rc > (typeof(rc))sizeof(*lmv1))
1462 if (rc < (typeof(rc))sizeof(*lmv1))
1463 RETURN(rc = rc > 0 ? -EINVAL : rc);
1465 if (buf->lb_buf == NULL || buf->lb_len == 0) {
1466 CLASSERT(sizeof(*lmv1) <= sizeof(info->lti_key));
1468 info->lti_buf.lb_buf = info->lti_key;
1469 info->lti_buf.lb_len = sizeof(*lmv1);
1470 rc = dt_xattr_get(env, dt_object_child(dt),
1471 &info->lti_buf, name);
1472 if (unlikely(rc != sizeof(*lmv1)))
1473 RETURN(rc = rc > 0 ? -EINVAL : rc);
1475 lmv1 = info->lti_buf.lb_buf;
1476 /* The on-disk LMV EA only contains header, but the
1477 * returned LMV EA size should contain the space for
1478 * the FIDs of all shards of the striped directory. */
1479 if (le32_to_cpu(lmv1->lmv_magic) == LMV_MAGIC_V1)
1480 rc = lmv_mds_md_size(
1481 le32_to_cpu(lmv1->lmv_stripe_count),
1484 rc1 = lod_load_lmv_shards(env, lod_dt_obj(dt),
1488 RETURN(rc = rc1 != 0 ? rc1 : rc);
1491 if (rc != -ENODATA || !S_ISDIR(dt->do_lu.lo_header->loh_attr & S_IFMT))
1495 * XXX: Only used by lfsck
1497 * lod returns default striping on the real root of the device
1498 * this is like the root stores default striping for the whole
1499 * filesystem. historically we've been using a different approach
1500 * and store it in the config.
1502 dt_root_get(env, dev->lod_child, &info->lti_fid);
1503 is_root = lu_fid_eq(&info->lti_fid, lu_object_fid(&dt->do_lu));
1505 if (is_root && strcmp(XATTR_NAME_LOV, name) == 0) {
1506 struct lov_user_md *lum = buf->lb_buf;
1507 struct lov_desc *desc = &dev->lod_desc;
1509 if (buf->lb_buf == NULL) {
1511 } else if (buf->lb_len >= sizeof(*lum)) {
1512 lum->lmm_magic = cpu_to_le32(LOV_USER_MAGIC_V1);
1513 lmm_oi_set_seq(&lum->lmm_oi, FID_SEQ_LOV_DEFAULT);
1514 lmm_oi_set_id(&lum->lmm_oi, 0);
1515 lmm_oi_cpu_to_le(&lum->lmm_oi, &lum->lmm_oi);
1516 lum->lmm_pattern = cpu_to_le32(desc->ld_pattern);
1517 lum->lmm_stripe_size = cpu_to_le32(
1518 desc->ld_default_stripe_size);
1519 lum->lmm_stripe_count = cpu_to_le16(
1520 desc->ld_default_stripe_count);
1521 lum->lmm_stripe_offset = cpu_to_le16(
1522 desc->ld_default_stripe_offset);
1535 * Checks that the magic of the stripe is sane.
1537 * \param[in] lod lod device
1538 * \param[in] lum a buffer storing LMV EA to verify
1540 * \retval 0 if the EA is sane
1541 * \retval negative otherwise
1543 static int lod_verify_md_striping(struct lod_device *lod,
1544 const struct lmv_user_md_v1 *lum)
1546 if (unlikely(le32_to_cpu(lum->lum_magic) != LMV_USER_MAGIC)) {
1547 CERROR("%s: invalid lmv_user_md: magic = %x, "
1548 "stripe_offset = %d, stripe_count = %u: rc = %d\n",
1549 lod2obd(lod)->obd_name, le32_to_cpu(lum->lum_magic),
1550 (int)le32_to_cpu(lum->lum_stripe_offset),
1551 le32_to_cpu(lum->lum_stripe_count), -EINVAL);
1559 * Initialize LMV EA for a slave.
1561 * Initialize slave's LMV EA from the master's LMV EA.
1563 * \param[in] master_lmv a buffer containing master's EA
1564 * \param[out] slave_lmv a buffer where slave's EA will be stored
1567 static void lod_prep_slave_lmv_md(struct lmv_mds_md_v1 *slave_lmv,
1568 const struct lmv_mds_md_v1 *master_lmv)
1570 *slave_lmv = *master_lmv;
1571 slave_lmv->lmv_magic = cpu_to_le32(LMV_MAGIC_STRIPE);
1577 * Generate LMV EA from the object passed as \a dt. The object must have
1578 * the stripes created and initialized.
1580 * \param[in] env execution environment
1581 * \param[in] dt object
1582 * \param[out] lmv_buf buffer storing generated LMV EA
1584 * \retval 0 on success
1585 * \retval negative if failed
1587 static int lod_prep_lmv_md(const struct lu_env *env, struct dt_object *dt,
1588 struct lu_buf *lmv_buf)
1590 struct lod_thread_info *info = lod_env_info(env);
1591 struct lod_device *lod = lu2lod_dev(dt->do_lu.lo_dev);
1592 struct lod_object *lo = lod_dt_obj(dt);
1593 struct lmv_mds_md_v1 *lmm1;
1595 int type = LU_SEQ_RANGE_ANY;
1600 LASSERT(lo->ldo_dir_striped != 0);
1601 LASSERT(lo->ldo_dir_stripe_count > 0);
1602 stripe_count = lo->ldo_dir_stripe_count;
1603 /* Only store the LMV EA heahder on the disk. */
1604 if (info->lti_ea_store_size < sizeof(*lmm1)) {
1605 rc = lod_ea_store_resize(info, sizeof(*lmm1));
1609 memset(info->lti_ea_store, 0, sizeof(*lmm1));
1612 lmm1 = (struct lmv_mds_md_v1 *)info->lti_ea_store;
1613 memset(lmm1, 0, sizeof(*lmm1));
1614 lmm1->lmv_magic = cpu_to_le32(LMV_MAGIC);
1615 lmm1->lmv_stripe_count = cpu_to_le32(stripe_count);
1616 lmm1->lmv_hash_type = cpu_to_le32(lo->ldo_dir_hash_type);
1617 if (lo->ldo_dir_hash_type & LMV_HASH_FLAG_MIGRATION) {
1618 lmm1->lmv_migrate_hash = cpu_to_le32(lo->ldo_dir_migrate_hash);
1619 lmm1->lmv_migrate_offset =
1620 cpu_to_le32(lo->ldo_dir_migrate_offset);
1622 rc = lod_fld_lookup(env, lod, lu_object_fid(&dt->do_lu),
1627 lmm1->lmv_master_mdt_index = cpu_to_le32(mdtidx);
1628 lmv_buf->lb_buf = info->lti_ea_store;
1629 lmv_buf->lb_len = sizeof(*lmm1);
1635 * Create in-core represenation for a striped directory.
1637 * Parse the buffer containing LMV EA and instantiate LU objects
1638 * representing the stripe objects. The pointers to the objects are
1639 * stored in ldo_stripe field of \a lo. This function is used when
1640 * we need to access an already created object (i.e. load from a disk).
1642 * \param[in] env execution environment
1643 * \param[in] lo lod object
1644 * \param[in] buf buffer containing LMV EA
1646 * \retval 0 on success
1647 * \retval negative if failed
1649 int lod_parse_dir_striping(const struct lu_env *env, struct lod_object *lo,
1650 const struct lu_buf *buf)
1652 struct lod_thread_info *info = lod_env_info(env);
1653 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
1654 struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
1655 struct dt_object **stripe;
1656 union lmv_mds_md *lmm = buf->lb_buf;
1657 struct lmv_mds_md_v1 *lmv1 = &lmm->lmv_md_v1;
1658 struct lu_fid *fid = &info->lti_fid;
1663 LASSERT(mutex_is_locked(&lo->ldo_layout_mutex));
1665 if (le32_to_cpu(lmv1->lmv_magic) == LMV_MAGIC_STRIPE) {
1666 lo->ldo_dir_slave_stripe = 1;
1670 if (le32_to_cpu(lmv1->lmv_magic) != LMV_MAGIC_V1)
1673 if (le32_to_cpu(lmv1->lmv_stripe_count) < 1)
1676 LASSERT(lo->ldo_stripe == NULL);
1677 OBD_ALLOC(stripe, sizeof(stripe[0]) *
1678 (le32_to_cpu(lmv1->lmv_stripe_count)));
1682 for (i = 0; i < le32_to_cpu(lmv1->lmv_stripe_count); i++) {
1683 struct dt_device *tgt_dt;
1684 struct dt_object *dto;
1685 int type = LU_SEQ_RANGE_ANY;
1688 fid_le_to_cpu(fid, &lmv1->lmv_stripe_fids[i]);
1689 if (!fid_is_sane(fid))
1690 GOTO(out, rc = -ESTALE);
1692 rc = lod_fld_lookup(env, lod, fid, &idx, &type);
1696 if (idx == lod2lu_dev(lod)->ld_site->ld_seq_site->ss_node_id) {
1697 tgt_dt = lod->lod_child;
1699 struct lod_tgt_desc *tgt;
1701 tgt = LTD_TGT(ltd, idx);
1703 GOTO(out, rc = -ESTALE);
1704 tgt_dt = tgt->ltd_tgt;
1707 dto = dt_locate_at(env, tgt_dt, fid,
1708 lo->ldo_obj.do_lu.lo_dev->ld_site->ls_top_dev,
1711 GOTO(out, rc = PTR_ERR(dto));
1716 lo->ldo_stripe = stripe;
1717 lo->ldo_dir_stripe_count = le32_to_cpu(lmv1->lmv_stripe_count);
1718 lo->ldo_dir_stripes_allocated = le32_to_cpu(lmv1->lmv_stripe_count);
1720 lod_striping_free_nolock(env, lo);
1726 * Declare create a striped directory.
1728 * Declare creating a striped directory with a given stripe pattern on the
1729 * specified MDTs. A striped directory is represented as a regular directory
1730 * - an index listing all the stripes. The stripes point back to the master
1731 * object with ".." and LinkEA. The master object gets LMV EA which
1732 * identifies it as a striped directory. The function allocates FIDs
1735 * \param[in] env execution environment
1736 * \param[in] dt object
1737 * \param[in] attr attributes to initialize the objects with
1738 * \param[in] dof type of objects to be created
1739 * \param[in] th transaction handle
1741 * \retval 0 on success
1742 * \retval negative if failed
1744 static int lod_dir_declare_create_stripes(const struct lu_env *env,
1745 struct dt_object *dt,
1746 struct lu_attr *attr,
1747 struct dt_object_format *dof,
1750 struct lod_thread_info *info = lod_env_info(env);
1751 struct lu_buf lmv_buf;
1752 struct lu_buf slave_lmv_buf;
1753 struct lmv_mds_md_v1 *lmm;
1754 struct lmv_mds_md_v1 *slave_lmm = NULL;
1755 struct dt_insert_rec *rec = &info->lti_dt_rec;
1756 struct lod_object *lo = lod_dt_obj(dt);
1761 rc = lod_prep_lmv_md(env, dt, &lmv_buf);
1764 lmm = lmv_buf.lb_buf;
1766 OBD_ALLOC_PTR(slave_lmm);
1767 if (slave_lmm == NULL)
1768 GOTO(out, rc = -ENOMEM);
1770 lod_prep_slave_lmv_md(slave_lmm, lmm);
1771 slave_lmv_buf.lb_buf = slave_lmm;
1772 slave_lmv_buf.lb_len = sizeof(*slave_lmm);
1774 if (!dt_try_as_dir(env, dt_object_child(dt)))
1775 GOTO(out, rc = -EINVAL);
1777 rec->rec_type = S_IFDIR;
1778 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
1779 struct dt_object *dto = lo->ldo_stripe[i];
1780 char *stripe_name = info->lti_key;
1781 struct lu_name *sname;
1782 struct linkea_data ldata = { NULL };
1783 struct lu_buf linkea_buf;
1785 rc = lod_sub_declare_create(env, dto, attr, NULL, dof, th);
1789 if (!dt_try_as_dir(env, dto))
1790 GOTO(out, rc = -EINVAL);
1792 rc = lod_sub_declare_ref_add(env, dto, th);
1796 rec->rec_fid = lu_object_fid(&dto->do_lu);
1797 rc = lod_sub_declare_insert(env, dto,
1798 (const struct dt_rec *)rec,
1799 (const struct dt_key *)dot, th);
1803 /* master stripe FID will be put to .. */
1804 rec->rec_fid = lu_object_fid(&dt->do_lu);
1805 rc = lod_sub_declare_insert(env, dto,
1806 (const struct dt_rec *)rec,
1807 (const struct dt_key *)dotdot, th);
1811 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_SLAVE_LMV) ||
1812 cfs_fail_val != i) {
1813 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_SLAVE_LMV) &&
1815 slave_lmm->lmv_master_mdt_index =
1818 slave_lmm->lmv_master_mdt_index =
1820 rc = lod_sub_declare_xattr_set(env, dto, &slave_lmv_buf,
1821 XATTR_NAME_LMV, 0, th);
1826 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_SLAVE_NAME) &&
1828 snprintf(stripe_name, sizeof(info->lti_key), DFID":%u",
1829 PFID(lu_object_fid(&dto->do_lu)), i + 1);
1831 snprintf(stripe_name, sizeof(info->lti_key), DFID":%u",
1832 PFID(lu_object_fid(&dto->do_lu)), i);
1834 sname = lod_name_get(env, stripe_name, strlen(stripe_name));
1835 rc = linkea_links_new(&ldata, &info->lti_linkea_buf,
1836 sname, lu_object_fid(&dt->do_lu));
1840 linkea_buf.lb_buf = ldata.ld_buf->lb_buf;
1841 linkea_buf.lb_len = ldata.ld_leh->leh_len;
1842 rc = lod_sub_declare_xattr_set(env, dto, &linkea_buf,
1843 XATTR_NAME_LINK, 0, th);
1847 rec->rec_fid = lu_object_fid(&dto->do_lu);
1848 rc = lod_sub_declare_insert(env, dt_object_child(dt),
1849 (const struct dt_rec *)rec,
1850 (const struct dt_key *)stripe_name,
1855 rc = lod_sub_declare_ref_add(env, dt_object_child(dt), th);
1860 rc = lod_sub_declare_xattr_set(env, dt_object_child(dt),
1861 &lmv_buf, XATTR_NAME_LMV, 0, th);
1865 if (slave_lmm != NULL)
1866 OBD_FREE_PTR(slave_lmm);
1871 static int lod_prep_md_striped_create(const struct lu_env *env,
1872 struct dt_object *dt,
1873 struct lu_attr *attr,
1874 const struct lmv_user_md_v1 *lum,
1875 struct dt_object_format *dof,
1878 struct lod_thread_info *info = lod_env_info(env);
1879 struct lod_device *lod = lu2lod_dev(dt->do_lu.lo_dev);
1880 struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
1881 struct lod_object *lo = lod_dt_obj(dt);
1882 struct dt_object **stripe;
1889 bool is_specific = false;
1892 /* The lum has been verifed in lod_verify_md_striping */
1893 LASSERT(le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC ||
1894 le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC_SPECIFIC);
1896 stripe_count = lo->ldo_dir_stripe_count;
1898 OBD_ALLOC(idx_array, sizeof(idx_array[0]) * stripe_count);
1899 if (idx_array == NULL)
1902 OBD_ALLOC(stripe, sizeof(stripe[0]) * stripe_count);
1904 GOTO(out_free, rc = -ENOMEM);
1906 /* Start index must be the master MDT */
1907 master_index = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
1908 idx_array[0] = master_index;
1909 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC_SPECIFIC) {
1911 for (i = 1; i < stripe_count; i++)
1912 idx_array[i] = le32_to_cpu(lum->lum_objects[i].lum_mds);
1915 for (i = 0; i < stripe_count; i++) {
1916 struct lod_tgt_desc *tgt = NULL;
1917 struct dt_object *dto;
1918 struct lu_fid fid = { 0 };
1920 struct lu_object_conf conf = { 0 };
1921 struct dt_device *tgt_dt = NULL;
1923 /* Try to find next avaible target */
1925 for (j = 0; j < lod->lod_remote_mdt_count;
1926 j++, idx = (idx + 1) % (lod->lod_remote_mdt_count + 1)) {
1927 bool already_allocated = false;
1930 CDEBUG(D_INFO, "try idx %d, mdt cnt %u, allocated %u\n",
1931 idx, lod->lod_remote_mdt_count + 1, i);
1933 if (likely(!is_specific &&
1934 !OBD_FAIL_CHECK(OBD_FAIL_LARGE_STRIPE))) {
1935 /* check whether the idx already exists
1936 * in current allocated array */
1937 for (k = 0; k < i; k++) {
1938 if (idx_array[k] == idx) {
1939 already_allocated = true;
1944 if (already_allocated)
1948 /* Sigh, this index is not in the bitmap, let's check
1949 * next available target */
1950 if (!cfs_bitmap_check(ltd->ltd_tgt_bitmap, idx) &&
1951 idx != master_index)
1954 if (idx == master_index) {
1955 /* Allocate the FID locally */
1956 rc = obd_fid_alloc(env, lod->lod_child_exp,
1960 tgt_dt = lod->lod_child;
1964 /* check the status of the OSP */
1965 tgt = LTD_TGT(ltd, idx);
1969 tgt_dt = tgt->ltd_tgt;
1970 rc = dt_statfs(env, tgt_dt, &info->lti_osfs);
1972 /* this OSP doesn't feel well */
1977 rc = obd_fid_alloc(env, tgt->ltd_exp, &fid, NULL);
1986 /* Can not allocate more stripes */
1987 if (j == lod->lod_remote_mdt_count) {
1988 CDEBUG(D_INFO, "%s: require stripes %u only get %d\n",
1989 lod2obd(lod)->obd_name, stripe_count, i);
1993 CDEBUG(D_INFO, "Get idx %d, for stripe %d "DFID"\n",
1994 idx, i, PFID(&fid));
1996 /* Set the start index for next stripe allocation */
1997 if (!is_specific && i < stripe_count - 1) {
1999 * for large dir test, put all other slaves on one
2000 * remote MDT, otherwise we may save too many local
2001 * slave locks which will exceed RS_MAX_LOCKS.
2003 if (unlikely(OBD_FAIL_CHECK(OBD_FAIL_LARGE_STRIPE)))
2005 idx_array[i + 1] = (idx + 1) %
2006 (lod->lod_remote_mdt_count + 1);
2008 /* tgt_dt and fid must be ready after search avaible OSP
2009 * in the above loop */
2010 LASSERT(tgt_dt != NULL);
2011 LASSERT(fid_is_sane(&fid));
2012 conf.loc_flags = LOC_F_NEW;
2013 dto = dt_locate_at(env, tgt_dt, &fid,
2014 dt->do_lu.lo_dev->ld_site->ls_top_dev,
2017 GOTO(out_put, rc = PTR_ERR(dto));
2021 lo->ldo_dir_striped = 1;
2022 lo->ldo_stripe = stripe;
2023 lo->ldo_dir_stripe_count = i;
2024 lo->ldo_dir_stripes_allocated = stripe_count;
2026 lo->ldo_dir_stripe_loaded = 1;
2028 if (lo->ldo_dir_stripe_count == 0)
2029 GOTO(out_put, rc = -ENOSPC);
2031 rc = lod_dir_declare_create_stripes(env, dt, attr, dof, th);
2037 for (i = 0; i < stripe_count; i++)
2038 if (stripe[i] != NULL)
2039 dt_object_put(env, stripe[i]);
2040 OBD_FREE(stripe, sizeof(stripe[0]) * stripe_count);
2041 lo->ldo_dir_stripe_count = 0;
2042 lo->ldo_dir_stripes_allocated = 0;
2043 lo->ldo_stripe = NULL;
2047 OBD_FREE(idx_array, sizeof(idx_array[0]) * stripe_count);
2053 * Declare create striped md object.
2055 * The function declares intention to create a striped directory. This is a
2056 * wrapper for lod_prep_md_striped_create(). The only additional functionality
2057 * is to verify pattern \a lum_buf is good. Check that function for the details.
2059 * \param[in] env execution environment
2060 * \param[in] dt object
2061 * \param[in] attr attributes to initialize the objects with
2062 * \param[in] lum_buf a pattern specifying the number of stripes and
2064 * \param[in] dof type of objects to be created
2065 * \param[in] th transaction handle
2067 * \retval 0 on success
2068 * \retval negative if failed
2071 static int lod_declare_xattr_set_lmv(const struct lu_env *env,
2072 struct dt_object *dt,
2073 struct lu_attr *attr,
2074 const struct lu_buf *lum_buf,
2075 struct dt_object_format *dof,
2078 struct lod_object *lo = lod_dt_obj(dt);
2079 struct lmv_user_md_v1 *lum = lum_buf->lb_buf;
2083 LASSERT(lum != NULL);
2085 CDEBUG(D_INFO, "lum magic = %x count = %u offset = %d\n",
2086 le32_to_cpu(lum->lum_magic), le32_to_cpu(lum->lum_stripe_count),
2087 (int)le32_to_cpu(lum->lum_stripe_offset));
2089 if (lo->ldo_dir_stripe_count == 0)
2092 /* prepare dir striped objects */
2093 rc = lod_prep_md_striped_create(env, dt, attr, lum, dof, th);
2095 /* failed to create striping, let's reset
2096 * config so that others don't get confused */
2097 lod_striping_free(env, lo);
2105 * Append source stripes after target stripes for migrating directory. NB, we
2106 * only need to declare this, the append is done inside lod_xattr_set_lmv().
2108 * \param[in] env execution environment
2109 * \param[in] dt target object
2110 * \param[in] buf LMV buf which contains source stripe fids
2111 * \param[in] th transaction handle
2113 * \retval 0 on success
2114 * \retval negative if failed
2116 static int lod_dir_declare_layout_add(const struct lu_env *env,
2117 struct dt_object *dt,
2118 const struct lu_buf *buf,
2121 struct lod_thread_info *info = lod_env_info(env);
2122 struct lod_device *lod = lu2lod_dev(dt->do_lu.lo_dev);
2123 struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
2124 struct lod_object *lo = lod_dt_obj(dt);
2125 struct dt_object *next = dt_object_child(dt);
2126 struct dt_object_format *dof = &info->lti_format;
2127 struct lmv_mds_md_v1 *lmv = buf->lb_buf;
2128 struct dt_object **stripe;
2129 __u32 stripe_count = le32_to_cpu(lmv->lmv_stripe_count);
2130 struct lu_fid *fid = &info->lti_fid;
2131 struct lod_tgt_desc *tgt;
2132 struct dt_object *dto;
2133 struct dt_device *tgt_dt;
2134 int type = LU_SEQ_RANGE_ANY;
2135 struct dt_insert_rec *rec = &info->lti_dt_rec;
2136 char *stripe_name = info->lti_key;
2137 struct lu_name *sname;
2138 struct linkea_data ldata = { NULL };
2139 struct lu_buf linkea_buf;
2146 if (le32_to_cpu(lmv->lmv_magic) != LMV_MAGIC_V1)
2149 if (stripe_count == 0)
2152 dof->dof_type = DFT_DIR;
2155 sizeof(*stripe) * (lo->ldo_dir_stripe_count + stripe_count));
2159 for (i = 0; i < lo->ldo_dir_stripe_count; i++)
2160 stripe[i] = lo->ldo_stripe[i];
2162 for (i = 0; i < stripe_count; i++) {
2164 &lmv->lmv_stripe_fids[i]);
2165 if (!fid_is_sane(fid))
2166 GOTO(out, rc = -ESTALE);
2168 rc = lod_fld_lookup(env, lod, fid, &idx, &type);
2172 if (idx == lod2lu_dev(lod)->ld_site->ld_seq_site->ss_node_id) {
2173 tgt_dt = lod->lod_child;
2175 tgt = LTD_TGT(ltd, idx);
2177 GOTO(out, rc = -ESTALE);
2178 tgt_dt = tgt->ltd_tgt;
2181 dto = dt_locate_at(env, tgt_dt, fid,
2182 lo->ldo_obj.do_lu.lo_dev->ld_site->ls_top_dev,
2185 GOTO(out, rc = PTR_ERR(dto));
2187 stripe[i + lo->ldo_dir_stripe_count] = dto;
2189 if (!dt_try_as_dir(env, dto))
2190 GOTO(out, rc = -ENOTDIR);
2192 rc = lod_sub_declare_ref_add(env, dto, th);
2196 rc = lod_sub_declare_insert(env, dto,
2197 (const struct dt_rec *)rec,
2198 (const struct dt_key *)dot, th);
2202 rc = lod_sub_declare_insert(env, dto,
2203 (const struct dt_rec *)rec,
2204 (const struct dt_key *)dotdot, th);
2208 rc = lod_sub_declare_xattr_set(env, dto, buf,
2209 XATTR_NAME_LMV, 0, th);
2213 snprintf(stripe_name, sizeof(info->lti_key), DFID":%u",
2214 PFID(lu_object_fid(&dto->do_lu)),
2215 i + lo->ldo_dir_stripe_count);
2217 sname = lod_name_get(env, stripe_name, strlen(stripe_name));
2218 rc = linkea_links_new(&ldata, &info->lti_linkea_buf,
2219 sname, lu_object_fid(&dt->do_lu));
2223 linkea_buf.lb_buf = ldata.ld_buf->lb_buf;
2224 linkea_buf.lb_len = ldata.ld_leh->leh_len;
2225 rc = lod_sub_declare_xattr_set(env, dto, &linkea_buf,
2226 XATTR_NAME_LINK, 0, th);
2230 rc = lod_sub_declare_insert(env, next,
2231 (const struct dt_rec *)rec,
2232 (const struct dt_key *)stripe_name,
2237 rc = lod_sub_declare_ref_add(env, next, th);
2243 OBD_FREE(lo->ldo_stripe,
2244 sizeof(*stripe) * lo->ldo_dir_stripes_allocated);
2245 lo->ldo_stripe = stripe;
2246 lo->ldo_dir_migrate_offset = lo->ldo_dir_stripe_count;
2247 lo->ldo_dir_migrate_hash = le32_to_cpu(lmv->lmv_hash_type);
2248 lo->ldo_dir_stripe_count += stripe_count;
2249 lo->ldo_dir_stripes_allocated += stripe_count;
2250 lo->ldo_dir_hash_type |= LMV_HASH_FLAG_MIGRATION;
2254 i = lo->ldo_dir_stripe_count;
2255 while (i < lo->ldo_dir_stripe_count + stripe_count && stripe[i])
2256 dt_object_put(env, stripe[i++]);
2259 sizeof(*stripe) * (stripe_count + lo->ldo_dir_stripe_count));
2263 static int lod_dir_declare_layout_delete(const struct lu_env *env,
2264 struct dt_object *dt,
2265 const struct lu_buf *buf,
2268 struct lod_thread_info *info = lod_env_info(env);
2269 struct lod_object *lo = lod_dt_obj(dt);
2270 struct dt_object *next = dt_object_child(dt);
2271 struct lmv_user_md *lmu = buf->lb_buf;
2272 __u32 final_stripe_count;
2273 char *stripe_name = info->lti_key;
2274 struct dt_object *dto;
2281 final_stripe_count = le32_to_cpu(lmu->lum_stripe_count);
2282 if (final_stripe_count >= lo->ldo_dir_stripe_count)
2285 for (i = final_stripe_count; i < lo->ldo_dir_stripe_count; i++) {
2286 dto = lo->ldo_stripe[i];
2289 if (!dt_try_as_dir(env, dto))
2292 rc = lod_sub_declare_delete(env, dto,
2293 (const struct dt_key *)dot, th);
2297 rc = lod_sub_declare_ref_del(env, dto, th);
2301 rc = lod_sub_declare_delete(env, dto,
2302 (const struct dt_key *)dotdot, th);
2306 snprintf(stripe_name, sizeof(info->lti_key), DFID":%d",
2307 PFID(lu_object_fid(&dto->do_lu)), i);
2309 rc = lod_sub_declare_delete(env, next,
2310 (const struct dt_key *)stripe_name, th);
2314 rc = lod_sub_declare_ref_del(env, next, th);
2323 * delete stripes from dir master object, the lum_stripe_count in argument is
2324 * the final stripe count, the stripes after that will be deleted, NB, they
2325 * are not destroyed, but deleted from it's parent namespace, this function
2326 * will be called in two places:
2327 * 1. mdd_migrate_create() delete stripes from source, and append them to
2329 * 2. mdd_dir_layout_shrink() delete stripes from source, and destroy them.
2331 static int lod_dir_layout_delete(const struct lu_env *env,
2332 struct dt_object *dt,
2333 const struct lu_buf *buf,
2336 struct lod_thread_info *info = lod_env_info(env);
2337 struct lod_object *lo = lod_dt_obj(dt);
2338 struct dt_object *next = dt_object_child(dt);
2339 struct lmv_user_md *lmu = buf->lb_buf;
2340 __u32 final_stripe_count;
2341 char *stripe_name = info->lti_key;
2342 struct dt_object *dto;
2351 final_stripe_count = le32_to_cpu(lmu->lum_stripe_count);
2352 if (final_stripe_count >= lo->ldo_dir_stripe_count)
2355 for (i = final_stripe_count; i < lo->ldo_dir_stripe_count; i++) {
2356 dto = lo->ldo_stripe[i];
2359 rc = lod_sub_delete(env, dto,
2360 (const struct dt_key *)dotdot, th);
2364 snprintf(stripe_name, sizeof(info->lti_key), DFID":%d",
2365 PFID(lu_object_fid(&dto->do_lu)), i);
2367 rc = lod_sub_delete(env, next,
2368 (const struct dt_key *)stripe_name, th);
2372 rc = lod_sub_ref_del(env, next, th);
2377 lod_striping_free(env, lod_dt_obj(dt));
2383 * Implementation of dt_object_operations::do_declare_xattr_set.
2385 * Used with regular (non-striped) objects. Basically it
2386 * initializes the striping information and applies the
2387 * change to all the stripes.
2389 * \see dt_object_operations::do_declare_xattr_set() in the API description
2392 static int lod_dir_declare_xattr_set(const struct lu_env *env,
2393 struct dt_object *dt,
2394 const struct lu_buf *buf,
2395 const char *name, int fl,
2398 struct dt_object *next = dt_object_child(dt);
2399 struct lod_device *d = lu2lod_dev(dt->do_lu.lo_dev);
2400 struct lod_object *lo = lod_dt_obj(dt);
2405 if (strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0) {
2406 struct lmv_user_md_v1 *lum;
2408 LASSERT(buf != NULL && buf->lb_buf != NULL);
2410 rc = lod_verify_md_striping(d, lum);
2413 } else if (strcmp(name, XATTR_NAME_LOV) == 0) {
2414 rc = lod_verify_striping(d, lo, buf, false);
2419 rc = lod_sub_declare_xattr_set(env, next, buf, name, fl, th);
2423 /* Note: Do not set LinkEA on sub-stripes, otherwise
2424 * it will confuse the fid2path process(see mdt_path_current()).
2425 * The linkEA between master and sub-stripes is set in
2426 * lod_xattr_set_lmv(). */
2427 if (strcmp(name, XATTR_NAME_LINK) == 0)
2430 /* set xattr to each stripes, if needed */
2431 rc = lod_striping_load(env, lo);
2435 if (lo->ldo_dir_stripe_count == 0)
2438 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
2439 LASSERT(lo->ldo_stripe[i]);
2441 rc = lod_sub_declare_xattr_set(env, lo->ldo_stripe[i],
2451 lod_obj_stripe_replace_parent_fid_cb(const struct lu_env *env,
2452 struct lod_object *lo,
2453 struct dt_object *dt, struct thandle *th,
2454 int comp_idx, int stripe_idx,
2455 struct lod_obj_stripe_cb_data *data)
2457 struct lod_thread_info *info = lod_env_info(env);
2458 struct lod_layout_component *comp = &lo->ldo_comp_entries[comp_idx];
2459 struct filter_fid *ff = &info->lti_ff;
2460 struct lu_buf *buf = &info->lti_buf;
2464 buf->lb_len = sizeof(*ff);
2465 rc = dt_xattr_get(env, dt, buf, XATTR_NAME_FID);
2473 * locd_buf is set if it's called by dir migration, which doesn't check
2476 if (data->locd_buf) {
2477 memset(ff, 0, sizeof(*ff));
2478 ff->ff_parent = *(struct lu_fid *)data->locd_buf->lb_buf;
2480 filter_fid_le_to_cpu(ff, ff, sizeof(*ff));
2482 if (lu_fid_eq(lod_object_fid(lo), &ff->ff_parent) &&
2483 ff->ff_layout.ol_comp_id == comp->llc_id)
2486 memset(ff, 0, sizeof(*ff));
2487 ff->ff_parent = *lu_object_fid(&lo->ldo_obj.do_lu);
2490 /* rewrite filter_fid */
2491 ff->ff_parent.f_ver = stripe_idx;
2492 ff->ff_layout.ol_stripe_size = comp->llc_stripe_size;
2493 ff->ff_layout.ol_stripe_count = comp->llc_stripe_count;
2494 ff->ff_layout.ol_comp_id = comp->llc_id;
2495 ff->ff_layout.ol_comp_start = comp->llc_extent.e_start;
2496 ff->ff_layout.ol_comp_end = comp->llc_extent.e_end;
2497 filter_fid_cpu_to_le(ff, ff, sizeof(*ff));
2499 if (data->locd_declare)
2500 rc = lod_sub_declare_xattr_set(env, dt, buf, XATTR_NAME_FID,
2501 LU_XATTR_REPLACE, th);
2503 rc = lod_sub_xattr_set(env, dt, buf, XATTR_NAME_FID,
2504 LU_XATTR_REPLACE, th);
2510 * Reset parent FID on OST object
2512 * Replace parent FID with @dt object FID, which is only called during migration
2513 * to reset the parent FID after the MDT object is migrated to the new MDT, i.e.
2514 * the FID is changed.
2516 * \param[in] env execution environment
2517 * \param[in] dt dt_object whose stripes's parent FID will be reset
2518 * \parem[in] th thandle
2519 * \param[in] declare if it is declare
2521 * \retval 0 if reset succeeds
2522 * \retval negative errno if reset fails
2524 static int lod_replace_parent_fid(const struct lu_env *env,
2525 struct dt_object *dt,
2526 const struct lu_buf *buf,
2527 struct thandle *th, bool declare)
2529 struct lod_object *lo = lod_dt_obj(dt);
2530 struct lod_thread_info *info = lod_env_info(env);
2531 struct filter_fid *ff;
2532 struct lod_obj_stripe_cb_data data = { { 0 } };
2536 LASSERT(S_ISREG(dt->do_lu.lo_header->loh_attr));
2538 /* set xattr to each stripes, if needed */
2539 rc = lod_striping_load(env, lo);
2543 if (!lod_obj_is_striped(dt))
2546 if (info->lti_ea_store_size < sizeof(*ff)) {
2547 rc = lod_ea_store_resize(info, sizeof(*ff));
2552 data.locd_declare = declare;
2553 data.locd_stripe_cb = lod_obj_stripe_replace_parent_fid_cb;
2554 data.locd_buf = buf;
2555 rc = lod_obj_for_each_stripe(env, lo, th, &data);
2560 inline __u16 lod_comp_entry_stripe_count(struct lod_object *lo,
2561 struct lod_layout_component *entry,
2564 struct lod_device *lod = lu2lod_dev(lod2lu_obj(lo)->lo_dev);
2568 else if (lod_comp_inited(entry))
2569 return entry->llc_stripe_count;
2570 else if ((__u16)-1 == entry->llc_stripe_count)
2571 return lod->lod_desc.ld_tgt_count;
2573 return lod_get_stripe_count(lod, lo, entry->llc_stripe_count);
2576 static int lod_comp_md_size(struct lod_object *lo, bool is_dir)
2578 int magic, size = 0, i;
2579 struct lod_layout_component *comp_entries;
2584 comp_cnt = lo->ldo_def_striping->lds_def_comp_cnt;
2585 comp_entries = lo->ldo_def_striping->lds_def_comp_entries;
2587 lo->ldo_def_striping->lds_def_striping_is_composite;
2589 comp_cnt = lo->ldo_comp_cnt;
2590 comp_entries = lo->ldo_comp_entries;
2591 is_composite = lo->ldo_is_composite;
2595 LASSERT(comp_cnt != 0 && comp_entries != NULL);
2597 size = sizeof(struct lov_comp_md_v1) +
2598 sizeof(struct lov_comp_md_entry_v1) * comp_cnt;
2599 LASSERT(size % sizeof(__u64) == 0);
2602 for (i = 0; i < comp_cnt; i++) {
2605 magic = comp_entries[i].llc_pool ? LOV_MAGIC_V3 : LOV_MAGIC_V1;
2606 stripe_count = lod_comp_entry_stripe_count(lo, &comp_entries[i],
2608 if (!is_dir && is_composite)
2609 lod_comp_shrink_stripe_count(&comp_entries[i],
2612 size += lov_user_md_size(stripe_count, magic);
2613 LASSERT(size % sizeof(__u64) == 0);
2619 * Declare component add. The xattr name is XATTR_LUSTRE_LOV.add, and
2620 * the xattr value is binary lov_comp_md_v1 which contains component(s)
2623 * \param[in] env execution environment
2624 * \param[in] dt dt_object to add components on
2625 * \param[in] buf buffer contains components to be added
2626 * \parem[in] th thandle
2628 * \retval 0 on success
2629 * \retval negative errno on failure
2631 static int lod_declare_layout_add(const struct lu_env *env,
2632 struct dt_object *dt,
2633 const struct lu_buf *buf,
2636 struct lod_thread_info *info = lod_env_info(env);
2637 struct lod_layout_component *comp_array, *lod_comp, *old_array;
2638 struct lod_device *d = lu2lod_dev(dt->do_lu.lo_dev);
2639 struct dt_object *next = dt_object_child(dt);
2640 struct lov_desc *desc = &d->lod_desc;
2641 struct lod_object *lo = lod_dt_obj(dt);
2642 struct lov_user_md_v3 *v3;
2643 struct lov_comp_md_v1 *comp_v1 = buf->lb_buf;
2645 int i, rc, array_cnt, old_array_cnt;
2648 LASSERT(lo->ldo_is_composite);
2650 if (lo->ldo_flr_state != LCM_FL_NONE)
2653 rc = lod_verify_striping(d, lo, buf, false);
2657 magic = comp_v1->lcm_magic;
2658 if (magic == __swab32(LOV_USER_MAGIC_COMP_V1)) {
2659 lustre_swab_lov_comp_md_v1(comp_v1);
2660 magic = comp_v1->lcm_magic;
2663 if (magic != LOV_USER_MAGIC_COMP_V1)
2666 array_cnt = lo->ldo_comp_cnt + comp_v1->lcm_entry_count;
2667 OBD_ALLOC(comp_array, sizeof(*comp_array) * array_cnt);
2668 if (comp_array == NULL)
2671 memcpy(comp_array, lo->ldo_comp_entries,
2672 sizeof(*comp_array) * lo->ldo_comp_cnt);
2674 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
2675 struct lov_user_md_v1 *v1;
2676 struct lu_extent *ext;
2678 v1 = (struct lov_user_md *)((char *)comp_v1 +
2679 comp_v1->lcm_entries[i].lcme_offset);
2680 ext = &comp_v1->lcm_entries[i].lcme_extent;
2682 lod_comp = &comp_array[lo->ldo_comp_cnt + i];
2683 lod_comp->llc_extent.e_start = ext->e_start;
2684 lod_comp->llc_extent.e_end = ext->e_end;
2685 lod_comp->llc_stripe_offset = v1->lmm_stripe_offset;
2686 lod_comp->llc_flags = comp_v1->lcm_entries[i].lcme_flags;
2688 lod_comp->llc_stripe_count = v1->lmm_stripe_count;
2689 lod_comp->llc_stripe_size = v1->lmm_stripe_size;
2690 lod_adjust_stripe_info(lod_comp, desc);
2692 if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
2693 v3 = (struct lov_user_md_v3 *) v1;
2694 if (v3->lmm_pool_name[0] != '\0') {
2695 rc = lod_set_pool(&lod_comp->llc_pool,
2703 old_array = lo->ldo_comp_entries;
2704 old_array_cnt = lo->ldo_comp_cnt;
2706 lo->ldo_comp_entries = comp_array;
2707 lo->ldo_comp_cnt = array_cnt;
2709 /* No need to increase layout generation here, it will be increased
2710 * later when generating component ID for the new components */
2712 info->lti_buf.lb_len = lod_comp_md_size(lo, false);
2713 rc = lod_sub_declare_xattr_set(env, next, &info->lti_buf,
2714 XATTR_NAME_LOV, 0, th);
2716 lo->ldo_comp_entries = old_array;
2717 lo->ldo_comp_cnt = old_array_cnt;
2721 OBD_FREE(old_array, sizeof(*lod_comp) * old_array_cnt);
2723 LASSERT(lo->ldo_mirror_count == 1);
2724 lo->ldo_mirrors[0].lme_end = array_cnt - 1;
2729 for (i = lo->ldo_comp_cnt; i < array_cnt; i++) {
2730 lod_comp = &comp_array[i];
2731 if (lod_comp->llc_pool != NULL) {
2732 OBD_FREE(lod_comp->llc_pool,
2733 strlen(lod_comp->llc_pool) + 1);
2734 lod_comp->llc_pool = NULL;
2737 OBD_FREE(comp_array, sizeof(*comp_array) * array_cnt);
2742 * Declare component set. The xattr is name XATTR_LUSTRE_LOV.set.$field,
2743 * the '$field' can only be 'flags' now. The xattr value is binary
2744 * lov_comp_md_v1 which contains the component ID(s) and the value of
2745 * the field to be modified.
2747 * \param[in] env execution environment
2748 * \param[in] dt dt_object to be modified
2749 * \param[in] op operation string, like "set.flags"
2750 * \param[in] buf buffer contains components to be set
2751 * \parem[in] th thandle
2753 * \retval 0 on success
2754 * \retval negative errno on failure
2756 static int lod_declare_layout_set(const struct lu_env *env,
2757 struct dt_object *dt,
2758 char *op, const struct lu_buf *buf,
2761 struct lod_layout_component *lod_comp;
2762 struct lod_thread_info *info = lod_env_info(env);
2763 struct lod_device *d = lu2lod_dev(dt->do_lu.lo_dev);
2764 struct lod_object *lo = lod_dt_obj(dt);
2765 struct lov_comp_md_v1 *comp_v1 = buf->lb_buf;
2768 bool changed = false;
2771 if (strcmp(op, "set.flags") != 0) {
2772 CDEBUG(D_LAYOUT, "%s: operation (%s) not supported.\n",
2773 lod2obd(d)->obd_name, op);
2777 magic = comp_v1->lcm_magic;
2778 if (magic == __swab32(LOV_USER_MAGIC_COMP_V1)) {
2779 lustre_swab_lov_comp_md_v1(comp_v1);
2780 magic = comp_v1->lcm_magic;
2783 if (magic != LOV_USER_MAGIC_COMP_V1)
2786 if (comp_v1->lcm_entry_count == 0) {
2787 CDEBUG(D_LAYOUT, "%s: entry count is zero.\n",
2788 lod2obd(d)->obd_name);
2792 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
2793 __u32 id = comp_v1->lcm_entries[i].lcme_id;
2794 __u32 flags = comp_v1->lcm_entries[i].lcme_flags;
2795 __u32 mirror_flag = flags & LCME_MIRROR_FLAGS;
2796 bool neg = flags & LCME_FL_NEG;
2798 if (flags & LCME_FL_INIT) {
2800 lod_striping_free(env, lo);
2804 flags &= ~(LCME_MIRROR_FLAGS | LCME_FL_NEG);
2805 for (j = 0; j < lo->ldo_comp_cnt; j++) {
2806 lod_comp = &lo->ldo_comp_entries[j];
2808 /* lfs only put one flag in each entry */
2809 if ((flags && id != lod_comp->llc_id) ||
2810 (mirror_flag && mirror_id_of(id) !=
2811 mirror_id_of(lod_comp->llc_id)))
2816 lod_comp->llc_flags &= ~flags;
2818 lod_comp->llc_flags &= ~mirror_flag;
2821 lod_comp->llc_flags |= flags;
2823 lod_comp->llc_flags |= mirror_flag;
2824 if (mirror_flag & LCME_FL_NOSYNC)
2825 lod_comp->llc_timestamp =
2826 ktime_get_real_seconds();
2834 CDEBUG(D_LAYOUT, "%s: requested component(s) not found.\n",
2835 lod2obd(d)->obd_name);
2839 lod_obj_inc_layout_gen(lo);
2841 info->lti_buf.lb_len = lod_comp_md_size(lo, false);
2842 rc = lod_sub_declare_xattr_set(env, dt_object_child(dt), &info->lti_buf,
2843 XATTR_NAME_LOV, LU_XATTR_REPLACE, th);
2848 * Declare component deletion. The xattr name is XATTR_LUSTRE_LOV.del,
2849 * and the xattr value is a unique component ID or a special lcme_id.
2851 * \param[in] env execution environment
2852 * \param[in] dt dt_object to be operated on
2853 * \param[in] buf buffer contains component ID or lcme_id
2854 * \parem[in] th thandle
2856 * \retval 0 on success
2857 * \retval negative errno on failure
2859 static int lod_declare_layout_del(const struct lu_env *env,
2860 struct dt_object *dt,
2861 const struct lu_buf *buf,
2864 struct lod_thread_info *info = lod_env_info(env);
2865 struct dt_object *next = dt_object_child(dt);
2866 struct lod_device *d = lu2lod_dev(dt->do_lu.lo_dev);
2867 struct lod_object *lo = lod_dt_obj(dt);
2868 struct lu_attr *attr = &lod_env_info(env)->lti_attr;
2869 struct lov_comp_md_v1 *comp_v1 = buf->lb_buf;
2870 __u32 magic, id, flags, neg_flags = 0;
2874 LASSERT(lo->ldo_is_composite);
2876 if (lo->ldo_flr_state != LCM_FL_NONE)
2879 magic = comp_v1->lcm_magic;
2880 if (magic == __swab32(LOV_USER_MAGIC_COMP_V1)) {
2881 lustre_swab_lov_comp_md_v1(comp_v1);
2882 magic = comp_v1->lcm_magic;
2885 if (magic != LOV_USER_MAGIC_COMP_V1)
2888 id = comp_v1->lcm_entries[0].lcme_id;
2889 flags = comp_v1->lcm_entries[0].lcme_flags;
2891 if (id > LCME_ID_MAX || (flags & ~LCME_KNOWN_FLAGS)) {
2892 CDEBUG(D_LAYOUT, "%s: invalid component id %#x, flags %#x\n",
2893 lod2obd(d)->obd_name, id, flags);
2897 if (id != LCME_ID_INVAL && flags != 0) {
2898 CDEBUG(D_LAYOUT, "%s: specified both id and flags.\n",
2899 lod2obd(d)->obd_name);
2903 if (id == LCME_ID_INVAL && !flags) {
2904 CDEBUG(D_LAYOUT, "%s: no id or flags specified.\n",
2905 lod2obd(d)->obd_name);
2909 if (flags & LCME_FL_NEG) {
2910 neg_flags = flags & ~LCME_FL_NEG;
2914 left = lo->ldo_comp_cnt;
2918 for (i = (lo->ldo_comp_cnt - 1); i >= 0; i--) {
2919 struct lod_layout_component *lod_comp;
2921 lod_comp = &lo->ldo_comp_entries[i];
2923 if (id != LCME_ID_INVAL && id != lod_comp->llc_id)
2925 else if (flags && !(flags & lod_comp->llc_flags))
2927 else if (neg_flags && (neg_flags & lod_comp->llc_flags))
2930 if (left != (i + 1)) {
2931 CDEBUG(D_LAYOUT, "%s: this deletion will create "
2932 "a hole.\n", lod2obd(d)->obd_name);
2937 /* Mark the component as deleted */
2938 lod_comp->llc_id = LCME_ID_INVAL;
2940 /* Not instantiated component */
2941 if (lod_comp->llc_stripe == NULL)
2944 LASSERT(lod_comp->llc_stripe_count > 0);
2945 for (j = 0; j < lod_comp->llc_stripe_count; j++) {
2946 struct dt_object *obj = lod_comp->llc_stripe[j];
2950 rc = lod_sub_declare_destroy(env, obj, th);
2956 LASSERTF(left >= 0, "left = %d\n", left);
2957 if (left == lo->ldo_comp_cnt) {
2958 CDEBUG(D_LAYOUT, "%s: requested component id:%#x not found\n",
2959 lod2obd(d)->obd_name, id);
2963 memset(attr, 0, sizeof(*attr));
2964 attr->la_valid = LA_SIZE;
2965 rc = lod_sub_declare_attr_set(env, next, attr, th);
2970 info->lti_buf.lb_len = lod_comp_md_size(lo, false);
2971 rc = lod_sub_declare_xattr_set(env, next, &info->lti_buf,
2972 XATTR_NAME_LOV, 0, th);
2974 rc = lod_sub_declare_xattr_del(env, next, XATTR_NAME_LOV, th);
2981 * Declare layout add/set/del operations issued by special xattr names:
2983 * XATTR_LUSTRE_LOV.add add component(s) to existing file
2984 * XATTR_LUSTRE_LOV.del delete component(s) from existing file
2985 * XATTR_LUSTRE_LOV.set.$field set specified field of certain component(s)
2987 * \param[in] env execution environment
2988 * \param[in] dt object
2989 * \param[in] name name of xattr
2990 * \param[in] buf lu_buf contains xattr value
2991 * \param[in] th transaction handle
2993 * \retval 0 on success
2994 * \retval negative if failed
2996 static int lod_declare_modify_layout(const struct lu_env *env,
2997 struct dt_object *dt,
2999 const struct lu_buf *buf,
3002 struct lod_device *d = lu2lod_dev(dt->do_lu.lo_dev);
3003 struct lod_object *lo = lod_dt_obj(dt);
3005 int rc, len = strlen(XATTR_LUSTRE_LOV);
3008 LASSERT(dt_object_exists(dt));
3010 if (strlen(name) <= len || name[len] != '.') {
3011 CDEBUG(D_LAYOUT, "%s: invalid xattr name: %s\n",
3012 lod2obd(d)->obd_name, name);
3017 rc = lod_striping_load(env, lo);
3021 /* the layout to be modified must be a composite layout */
3022 if (!lo->ldo_is_composite) {
3023 CDEBUG(D_LAYOUT, "%s: object "DFID" isn't a composite file.\n",
3024 lod2obd(d)->obd_name, PFID(lu_object_fid(&dt->do_lu)));
3025 GOTO(unlock, rc = -EINVAL);
3028 op = (char *)name + len;
3029 if (strcmp(op, "add") == 0) {
3030 rc = lod_declare_layout_add(env, dt, buf, th);
3031 } else if (strcmp(op, "del") == 0) {
3032 rc = lod_declare_layout_del(env, dt, buf, th);
3033 } else if (strncmp(op, "set", strlen("set")) == 0) {
3034 rc = lod_declare_layout_set(env, dt, op, buf, th);
3036 CDEBUG(D_LAYOUT, "%s: unsupported xattr name:%s\n",
3037 lod2obd(d)->obd_name, name);
3038 GOTO(unlock, rc = -ENOTSUPP);
3042 lod_striping_free(env, lo);
3048 * Convert a plain file lov_mds_md to a composite layout.
3050 * \param[in,out] info the thread info::lti_ea_store buffer contains little
3051 * endian plain file layout
3053 * \retval 0 on success, <0 on failure
3055 static int lod_layout_convert(struct lod_thread_info *info)
3057 struct lov_mds_md *lmm = info->lti_ea_store;
3058 struct lov_mds_md *lmm_save;
3059 struct lov_comp_md_v1 *lcm;
3060 struct lov_comp_md_entry_v1 *lcme;
3066 /* realloc buffer to a composite layout which contains one component */
3067 blob_size = lov_mds_md_size(le16_to_cpu(lmm->lmm_stripe_count),
3068 le32_to_cpu(lmm->lmm_magic));
3069 size = sizeof(*lcm) + sizeof(*lcme) + blob_size;
3071 OBD_ALLOC_LARGE(lmm_save, blob_size);
3073 GOTO(out, rc = -ENOMEM);
3075 memcpy(lmm_save, lmm, blob_size);
3077 if (info->lti_ea_store_size < size) {
3078 rc = lod_ea_store_resize(info, size);
3083 lcm = info->lti_ea_store;
3084 lcm->lcm_magic = cpu_to_le32(LOV_MAGIC_COMP_V1);
3085 lcm->lcm_size = cpu_to_le32(size);
3086 lcm->lcm_layout_gen = cpu_to_le32(le16_to_cpu(
3087 lmm_save->lmm_layout_gen));
3088 lcm->lcm_flags = cpu_to_le16(LCM_FL_NONE);
3089 lcm->lcm_entry_count = cpu_to_le16(1);
3090 lcm->lcm_mirror_count = 0;
3092 lcme = &lcm->lcm_entries[0];
3093 lcme->lcme_flags = cpu_to_le32(LCME_FL_INIT);
3094 lcme->lcme_extent.e_start = 0;
3095 lcme->lcme_extent.e_end = cpu_to_le64(OBD_OBJECT_EOF);
3096 lcme->lcme_offset = cpu_to_le32(sizeof(*lcm) + sizeof(*lcme));
3097 lcme->lcme_size = cpu_to_le32(blob_size);
3099 memcpy((char *)lcm + lcme->lcme_offset, (char *)lmm_save, blob_size);
3104 OBD_FREE_LARGE(lmm_save, blob_size);
3109 * Merge layouts to form a mirrored file.
3111 static int lod_declare_layout_merge(const struct lu_env *env,
3112 struct dt_object *dt, const struct lu_buf *mbuf,
3115 struct lod_thread_info *info = lod_env_info(env);
3116 struct lu_buf *buf = &info->lti_buf;
3117 struct lod_object *lo = lod_dt_obj(dt);
3118 struct lov_comp_md_v1 *lcm;
3119 struct lov_comp_md_v1 *cur_lcm;
3120 struct lov_comp_md_v1 *merge_lcm;
3121 struct lov_comp_md_entry_v1 *lcme;
3124 __u16 cur_entry_count;
3125 __u16 merge_entry_count;
3127 __u16 mirror_id = 0;
3132 merge_lcm = mbuf->lb_buf;
3133 if (mbuf->lb_len < sizeof(*merge_lcm))
3136 /* must be an existing layout from disk */
3137 if (le32_to_cpu(merge_lcm->lcm_magic) != LOV_MAGIC_COMP_V1)
3140 merge_entry_count = le16_to_cpu(merge_lcm->lcm_entry_count);
3142 /* do not allow to merge two mirrored files */
3143 if (le16_to_cpu(merge_lcm->lcm_mirror_count))
3146 /* verify the target buffer */
3147 rc = lod_get_lov_ea(env, lo);
3149 RETURN(rc ? : -ENODATA);
3151 cur_lcm = info->lti_ea_store;
3152 switch (le32_to_cpu(cur_lcm->lcm_magic)) {
3155 rc = lod_layout_convert(info);
3157 case LOV_MAGIC_COMP_V1:
3166 /* info->lti_ea_store could be reallocated in lod_layout_convert() */
3167 cur_lcm = info->lti_ea_store;
3168 cur_entry_count = le16_to_cpu(cur_lcm->lcm_entry_count);
3170 /* 'lcm_mirror_count + 1' is the current # of mirrors the file has */
3171 mirror_count = le16_to_cpu(cur_lcm->lcm_mirror_count) + 1;
3172 if (mirror_count + 1 > LUSTRE_MIRROR_COUNT_MAX)
3175 /* size of new layout */
3176 size = le32_to_cpu(cur_lcm->lcm_size) +
3177 le32_to_cpu(merge_lcm->lcm_size) - sizeof(*cur_lcm);
3179 memset(buf, 0, sizeof(*buf));
3180 lu_buf_alloc(buf, size);
3181 if (buf->lb_buf == NULL)
3185 memcpy(lcm, cur_lcm, sizeof(*lcm) + cur_entry_count * sizeof(*lcme));
3187 offset = sizeof(*lcm) +
3188 sizeof(*lcme) * (cur_entry_count + merge_entry_count);
3189 for (i = 0; i < cur_entry_count; i++) {
3190 struct lov_comp_md_entry_v1 *cur_lcme;
3192 lcme = &lcm->lcm_entries[i];
3193 cur_lcme = &cur_lcm->lcm_entries[i];
3195 lcme->lcme_offset = cpu_to_le32(offset);
3196 memcpy((char *)lcm + offset,
3197 (char *)cur_lcm + le32_to_cpu(cur_lcme->lcme_offset),
3198 le32_to_cpu(lcme->lcme_size));
3200 offset += le32_to_cpu(lcme->lcme_size);
3202 if (mirror_count == 1 &&
3203 mirror_id_of(le32_to_cpu(lcme->lcme_id)) == 0) {
3204 /* Add mirror from a non-flr file, create new mirror ID.
3205 * Otherwise, keep existing mirror's component ID, used
3206 * for mirror extension.
3208 id = pflr_id(1, i + 1);
3209 lcme->lcme_id = cpu_to_le32(id);
3212 id = MAX(le32_to_cpu(lcme->lcme_id), id);
3215 mirror_id = mirror_id_of(id) + 1;
3216 for (i = 0; i < merge_entry_count; i++) {
3217 struct lov_comp_md_entry_v1 *merge_lcme;
3219 merge_lcme = &merge_lcm->lcm_entries[i];
3220 lcme = &lcm->lcm_entries[cur_entry_count + i];
3222 *lcme = *merge_lcme;
3223 lcme->lcme_offset = cpu_to_le32(offset);
3225 id = pflr_id(mirror_id, i + 1);
3226 lcme->lcme_id = cpu_to_le32(id);
3228 memcpy((char *)lcm + offset,
3229 (char *)merge_lcm + le32_to_cpu(merge_lcme->lcme_offset),
3230 le32_to_cpu(lcme->lcme_size));
3232 offset += le32_to_cpu(lcme->lcme_size);
3235 /* fixup layout information */
3236 lod_obj_inc_layout_gen(lo);
3237 lcm->lcm_layout_gen = cpu_to_le32(lo->ldo_layout_gen);
3238 lcm->lcm_size = cpu_to_le32(size);
3239 lcm->lcm_entry_count = cpu_to_le16(cur_entry_count + merge_entry_count);
3240 lcm->lcm_mirror_count = cpu_to_le16(mirror_count);
3241 if ((le16_to_cpu(lcm->lcm_flags) & LCM_FL_FLR_MASK) == LCM_FL_NONE)
3242 lcm->lcm_flags = cpu_to_le32(LCM_FL_RDONLY);
3244 rc = lod_striping_reload(env, lo, buf);
3248 rc = lod_sub_declare_xattr_set(env, dt_object_child(dt), buf,
3249 XATTR_NAME_LOV, LU_XATTR_REPLACE, th);
3257 * Split layouts, just set the LOVEA with the layout from mbuf.
3259 static int lod_declare_layout_split(const struct lu_env *env,
3260 struct dt_object *dt, const struct lu_buf *mbuf,
3263 struct lod_object *lo = lod_dt_obj(dt);
3264 struct lov_comp_md_v1 *lcm = mbuf->lb_buf;
3268 lod_obj_inc_layout_gen(lo);
3269 lcm->lcm_layout_gen = cpu_to_le32(lo->ldo_layout_gen);
3271 rc = lod_striping_reload(env, lo, mbuf);
3275 rc = lod_sub_declare_xattr_set(env, dt_object_child(dt), mbuf,
3276 XATTR_NAME_LOV, LU_XATTR_REPLACE, th);
3281 * Implementation of dt_object_operations::do_declare_xattr_set.
3283 * \see dt_object_operations::do_declare_xattr_set() in the API description
3286 * the extension to the API:
3287 * - declaring LOVEA requests striping creation
3288 * - LU_XATTR_REPLACE means layout swap
3290 static int lod_declare_xattr_set(const struct lu_env *env,
3291 struct dt_object *dt,
3292 const struct lu_buf *buf,
3293 const char *name, int fl,
3296 struct dt_object *next = dt_object_child(dt);
3297 struct lu_attr *attr = &lod_env_info(env)->lti_attr;
3302 mode = dt->do_lu.lo_header->loh_attr & S_IFMT;
3303 if ((S_ISREG(mode) || mode == 0) &&
3304 !(fl & (LU_XATTR_REPLACE | LU_XATTR_MERGE | LU_XATTR_SPLIT)) &&
3305 (strcmp(name, XATTR_NAME_LOV) == 0 ||
3306 strcmp(name, XATTR_LUSTRE_LOV) == 0)) {
3308 * this is a request to create object's striping.
3310 * allow to declare predefined striping on a new (!mode) object
3311 * which is supposed to be replay of regular file creation
3312 * (when LOV setting is declared)
3314 * LU_XATTR_REPLACE is set to indicate a layout swap
3316 if (dt_object_exists(dt)) {
3317 rc = dt_attr_get(env, next, attr);
3321 memset(attr, 0, sizeof(*attr));
3322 attr->la_valid = LA_TYPE | LA_MODE;
3323 attr->la_mode = S_IFREG;
3325 rc = lod_declare_striped_create(env, dt, attr, buf, th);
3326 } else if (fl & LU_XATTR_MERGE) {
3327 LASSERT(strcmp(name, XATTR_NAME_LOV) == 0 ||
3328 strcmp(name, XATTR_LUSTRE_LOV) == 0);
3329 rc = lod_declare_layout_merge(env, dt, buf, th);
3330 } else if (fl & LU_XATTR_SPLIT) {
3331 LASSERT(strcmp(name, XATTR_NAME_LOV) == 0 ||
3332 strcmp(name, XATTR_LUSTRE_LOV) == 0);
3333 rc = lod_declare_layout_split(env, dt, buf, th);
3334 } else if (S_ISREG(mode) &&
3335 strlen(name) > strlen(XATTR_LUSTRE_LOV) + 1 &&
3336 strncmp(name, XATTR_LUSTRE_LOV,
3337 strlen(XATTR_LUSTRE_LOV)) == 0) {
3339 * this is a request to modify object's striping.
3340 * add/set/del component(s).
3342 if (!dt_object_exists(dt))
3345 rc = lod_declare_modify_layout(env, dt, name, buf, th);
3346 } else if (strncmp(name, XATTR_NAME_LMV, strlen(XATTR_NAME_LMV)) == 0 &&
3347 strlen(name) > strlen(XATTR_NAME_LMV) + 1) {
3348 const char *op = name + strlen(XATTR_NAME_LMV) + 1;
3351 if (strcmp(op, "add") == 0)
3352 rc = lod_dir_declare_layout_add(env, dt, buf, th);
3353 else if (strcmp(op, "del") == 0)
3354 rc = lod_dir_declare_layout_delete(env, dt, buf, th);
3355 else if (strcmp(op, "set") == 0)
3356 rc = lod_sub_declare_xattr_set(env, next, buf,
3357 XATTR_NAME_LMV, fl, th);
3360 } else if (S_ISDIR(mode)) {
3361 rc = lod_dir_declare_xattr_set(env, dt, buf, name, fl, th);
3362 } else if (strcmp(name, XATTR_NAME_FID) == 0) {
3363 rc = lod_replace_parent_fid(env, dt, buf, th, true);
3365 rc = lod_sub_declare_xattr_set(env, next, buf, name, fl, th);
3372 * Apply xattr changes to the object.
3374 * Applies xattr changes to the object and the stripes if the latter exist.
3376 * \param[in] env execution environment
3377 * \param[in] dt object
3378 * \param[in] buf buffer pointing to the new value of xattr
3379 * \param[in] name name of xattr
3380 * \param[in] fl flags
3381 * \param[in] th transaction handle
3383 * \retval 0 on success
3384 * \retval negative if failed
3386 static int lod_xattr_set_internal(const struct lu_env *env,
3387 struct dt_object *dt,
3388 const struct lu_buf *buf,
3389 const char *name, int fl,
3392 struct dt_object *next = dt_object_child(dt);
3393 struct lod_object *lo = lod_dt_obj(dt);
3398 rc = lod_sub_xattr_set(env, next, buf, name, fl, th);
3399 if (rc != 0 || !S_ISDIR(dt->do_lu.lo_header->loh_attr))
3402 /* Note: Do not set LinkEA on sub-stripes, otherwise
3403 * it will confuse the fid2path process(see mdt_path_current()).
3404 * The linkEA between master and sub-stripes is set in
3405 * lod_xattr_set_lmv(). */
3406 if (lo->ldo_dir_stripe_count == 0 || strcmp(name, XATTR_NAME_LINK) == 0)
3409 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
3410 LASSERT(lo->ldo_stripe[i]);
3412 rc = lod_sub_xattr_set(env, lo->ldo_stripe[i], buf, name,
3422 * Delete an extended attribute.
3424 * Deletes specified xattr from the object and the stripes if the latter exist.
3426 * \param[in] env execution environment
3427 * \param[in] dt object
3428 * \param[in] name name of xattr
3429 * \param[in] th transaction handle
3431 * \retval 0 on success
3432 * \retval negative if failed
3434 static int lod_xattr_del_internal(const struct lu_env *env,
3435 struct dt_object *dt,
3436 const char *name, struct thandle *th)
3438 struct dt_object *next = dt_object_child(dt);
3439 struct lod_object *lo = lod_dt_obj(dt);
3444 rc = lod_sub_xattr_del(env, next, name, th);
3445 if (rc != 0 || !S_ISDIR(dt->do_lu.lo_header->loh_attr))
3448 if (lo->ldo_dir_stripe_count == 0)
3451 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
3452 LASSERT(lo->ldo_stripe[i]);
3454 rc = lod_sub_xattr_del(env, lo->ldo_stripe[i], name, th);
3463 * Set default striping on a directory.
3465 * Sets specified striping on a directory object unless it matches the default
3466 * striping (LOVEA_DELETE_VALUES() macro). In the latter case remove existing
3467 * EA. This striping will be used when regular file is being created in this
3470 * \param[in] env execution environment
3471 * \param[in] dt the striped object
3472 * \param[in] buf buffer with the striping
3473 * \param[in] name name of EA
3474 * \param[in] fl xattr flag (see OSD API description)
3475 * \param[in] th transaction handle
3477 * \retval 0 on success
3478 * \retval negative if failed
3480 static int lod_xattr_set_lov_on_dir(const struct lu_env *env,
3481 struct dt_object *dt,
3482 const struct lu_buf *buf,
3483 const char *name, int fl,
3486 struct lov_user_md_v1 *lum;
3487 struct lov_user_md_v3 *v3 = NULL;
3488 const char *pool_name = NULL;
3493 LASSERT(buf != NULL && buf->lb_buf != NULL);
3496 switch (lum->lmm_magic) {
3497 case LOV_USER_MAGIC_SPECIFIC:
3498 case LOV_USER_MAGIC_V3:
3500 if (v3->lmm_pool_name[0] != '\0')
3501 pool_name = v3->lmm_pool_name;
3503 case LOV_USER_MAGIC_V1:
3504 /* if { size, offset, count } = { 0, -1, 0 } and no pool
3505 * (i.e. all default values specified) then delete default
3506 * striping from dir. */
3508 "set default striping: sz %u # %u offset %d %s %s\n",
3509 (unsigned)lum->lmm_stripe_size,
3510 (unsigned)lum->lmm_stripe_count,
3511 (int)lum->lmm_stripe_offset,
3512 v3 ? "from" : "", v3 ? v3->lmm_pool_name : "");
3514 is_del = LOVEA_DELETE_VALUES(lum->lmm_stripe_size,
3515 lum->lmm_stripe_count,
3516 lum->lmm_stripe_offset,
3519 case LOV_USER_MAGIC_COMP_V1:
3523 CERROR("Invalid magic %x\n", lum->lmm_magic);
3528 rc = lod_xattr_del_internal(env, dt, name, th);
3532 rc = lod_xattr_set_internal(env, dt, buf, name, fl, th);
3539 * Set default striping on a directory object.
3541 * Sets specified striping on a directory object unless it matches the default
3542 * striping (LOVEA_DELETE_VALUES() macro). In the latter case remove existing
3543 * EA. This striping will be used when a new directory is being created in the
3546 * \param[in] env execution environment
3547 * \param[in] dt the striped object
3548 * \param[in] buf buffer with the striping
3549 * \param[in] name name of EA
3550 * \param[in] fl xattr flag (see OSD API description)
3551 * \param[in] th transaction handle
3553 * \retval 0 on success
3554 * \retval negative if failed
3556 static int lod_xattr_set_default_lmv_on_dir(const struct lu_env *env,
3557 struct dt_object *dt,
3558 const struct lu_buf *buf,
3559 const char *name, int fl,
3562 struct lmv_user_md_v1 *lum;
3566 LASSERT(buf != NULL && buf->lb_buf != NULL);
3569 CDEBUG(D_OTHER, "set default stripe_count # %u stripe_offset %d\n",
3570 le32_to_cpu(lum->lum_stripe_count),
3571 (int)le32_to_cpu(lum->lum_stripe_offset));
3573 if (LMVEA_DELETE_VALUES((le32_to_cpu(lum->lum_stripe_count)),
3574 le32_to_cpu(lum->lum_stripe_offset)) &&
3575 le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
3576 rc = lod_xattr_del_internal(env, dt, name, th);
3580 rc = lod_xattr_set_internal(env, dt, buf, name, fl, th);
3589 * Turn directory into a striped directory.
3591 * During replay the client sends the striping created before MDT
3592 * failure, then the layer above LOD sends this defined striping
3593 * using ->do_xattr_set(), so LOD uses this method to replay creation
3594 * of the stripes. Notice the original information for the striping
3595 * (#stripes, FIDs, etc) was transferred in declare path.
3597 * \param[in] env execution environment
3598 * \param[in] dt the striped object
3599 * \param[in] buf not used currently
3600 * \param[in] name not used currently
3601 * \param[in] fl xattr flag (see OSD API description)
3602 * \param[in] th transaction handle
3604 * \retval 0 on success
3605 * \retval negative if failed
3607 static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
3608 const struct lu_buf *buf, const char *name,
3609 int fl, struct thandle *th)
3611 struct lod_object *lo = lod_dt_obj(dt);
3612 struct lod_thread_info *info = lod_env_info(env);
3613 struct lu_attr *attr = &info->lti_attr;
3614 struct dt_object_format *dof = &info->lti_format;
3615 struct lu_buf lmv_buf;
3616 struct lu_buf slave_lmv_buf;
3617 struct lmv_mds_md_v1 *lmm;
3618 struct lmv_mds_md_v1 *slave_lmm = NULL;
3619 struct dt_insert_rec *rec = &info->lti_dt_rec;
3624 if (!S_ISDIR(dt->do_lu.lo_header->loh_attr))
3627 /* The stripes are supposed to be allocated in declare phase,
3628 * if there are no stripes being allocated, it will skip */
3629 if (lo->ldo_dir_stripe_count == 0)
3632 rc = dt_attr_get(env, dt_object_child(dt), attr);
3636 attr->la_valid = LA_ATIME | LA_MTIME | LA_CTIME |
3637 LA_MODE | LA_UID | LA_GID | LA_TYPE | LA_PROJID;
3638 dof->dof_type = DFT_DIR;
3640 rc = lod_prep_lmv_md(env, dt, &lmv_buf);
3643 lmm = lmv_buf.lb_buf;
3645 OBD_ALLOC_PTR(slave_lmm);
3646 if (slave_lmm == NULL)
3649 lod_prep_slave_lmv_md(slave_lmm, lmm);
3650 slave_lmv_buf.lb_buf = slave_lmm;
3651 slave_lmv_buf.lb_len = sizeof(*slave_lmm);
3653 rec->rec_type = S_IFDIR;
3654 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
3655 struct dt_object *dto = lo->ldo_stripe[i];
3656 char *stripe_name = info->lti_key;
3657 struct lu_name *sname;
3658 struct linkea_data ldata = { NULL };
3659 struct lu_buf linkea_buf;
3661 /* if it's source stripe of migrating directory, don't create */
3662 if (!((lo->ldo_dir_hash_type & LMV_HASH_FLAG_MIGRATION) &&
3663 i >= lo->ldo_dir_migrate_offset)) {
3664 dt_write_lock(env, dto, MOR_TGT_CHILD);
3665 rc = lod_sub_create(env, dto, attr, NULL, dof, th);
3667 dt_write_unlock(env, dto);
3671 rc = lod_sub_ref_add(env, dto, th);
3672 dt_write_unlock(env, dto);
3676 rec->rec_fid = lu_object_fid(&dto->do_lu);
3677 rc = lod_sub_insert(env, dto,
3678 (const struct dt_rec *)rec,
3679 (const struct dt_key *)dot, th);
3684 rec->rec_fid = lu_object_fid(&dt->do_lu);
3685 rc = lod_sub_insert(env, dto, (struct dt_rec *)rec,
3686 (const struct dt_key *)dotdot, th);
3690 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_SLAVE_LMV) ||
3691 cfs_fail_val != i) {
3692 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_SLAVE_LMV) &&
3694 slave_lmm->lmv_master_mdt_index =
3697 slave_lmm->lmv_master_mdt_index =
3700 rc = lod_sub_xattr_set(env, dto, &slave_lmv_buf,
3701 XATTR_NAME_LMV, fl, th);
3706 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_SLAVE_NAME) &&
3708 snprintf(stripe_name, sizeof(info->lti_key), DFID":%d",
3709 PFID(lu_object_fid(&dto->do_lu)), i + 1);
3711 snprintf(stripe_name, sizeof(info->lti_key), DFID":%d",
3712 PFID(lu_object_fid(&dto->do_lu)), i);
3714 sname = lod_name_get(env, stripe_name, strlen(stripe_name));
3715 rc = linkea_links_new(&ldata, &info->lti_linkea_buf,
3716 sname, lu_object_fid(&dt->do_lu));
3720 linkea_buf.lb_buf = ldata.ld_buf->lb_buf;
3721 linkea_buf.lb_len = ldata.ld_leh->leh_len;
3722 rc = lod_sub_xattr_set(env, dto, &linkea_buf,
3723 XATTR_NAME_LINK, 0, th);
3727 rec->rec_fid = lu_object_fid(&dto->do_lu);
3728 rc = lod_sub_insert(env, dt_object_child(dt),
3729 (const struct dt_rec *)rec,
3730 (const struct dt_key *)stripe_name, th);
3734 rc = lod_sub_ref_add(env, dt_object_child(dt), th);
3739 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MASTER_LMV))
3740 rc = lod_sub_xattr_set(env, dt_object_child(dt),
3741 &lmv_buf, XATTR_NAME_LMV, fl, th);
3743 if (slave_lmm != NULL)
3744 OBD_FREE_PTR(slave_lmm);
3750 * Helper function to declare/execute creation of a striped directory
3752 * Called in declare/create object path, prepare striping for a directory
3753 * and prepare defaults data striping for the objects to be created in
3754 * that directory. Notice the function calls "declaration" or "execution"
3755 * methods depending on \a declare param. This is a consequence of the
3756 * current approach while we don't have natural distributed transactions:
3757 * we basically execute non-local updates in the declare phase. So, the
3758 * arguments for the both phases are the same and this is the reason for
3759 * this function to exist.
3761 * \param[in] env execution environment
3762 * \param[in] dt object
3763 * \param[in] attr attributes the stripes will be created with
3764 * \param[in] lmu lmv_user_md if MDT indices are specified
3765 * \param[in] dof format of stripes (see OSD API description)
3766 * \param[in] th transaction handle
3767 * \param[in] declare where to call "declare" or "execute" methods
3769 * \retval 0 on success
3770 * \retval negative if failed
3772 static int lod_dir_striping_create_internal(const struct lu_env *env,
3773 struct dt_object *dt,
3774 struct lu_attr *attr,
3775 const struct lu_buf *lmu,
3776 struct dt_object_format *dof,
3780 struct lod_thread_info *info = lod_env_info(env);
3781 struct lod_object *lo = lod_dt_obj(dt);
3782 const struct lod_default_striping *lds = lo->ldo_def_striping;
3786 LASSERT(ergo(lds != NULL,
3787 lds->lds_def_striping_set ||
3788 lds->lds_dir_def_striping_set));
3790 if (!LMVEA_DELETE_VALUES(lo->ldo_dir_stripe_count,
3791 lo->ldo_dir_stripe_offset)) {
3793 struct lmv_user_md_v1 *v1 = info->lti_ea_store;
3794 int stripe_count = lo->ldo_dir_stripe_count;
3796 if (info->lti_ea_store_size < sizeof(*v1)) {
3797 rc = lod_ea_store_resize(info, sizeof(*v1));
3800 v1 = info->lti_ea_store;
3803 memset(v1, 0, sizeof(*v1));
3804 v1->lum_magic = cpu_to_le32(LMV_USER_MAGIC);
3805 v1->lum_stripe_count = cpu_to_le32(stripe_count);
3806 v1->lum_stripe_offset =
3807 cpu_to_le32(lo->ldo_dir_stripe_offset);
3809 info->lti_buf.lb_buf = v1;
3810 info->lti_buf.lb_len = sizeof(*v1);
3811 lmu = &info->lti_buf;
3815 rc = lod_declare_xattr_set_lmv(env, dt, attr, lmu, dof,
3818 rc = lod_xattr_set_lmv(env, dt, lmu, XATTR_NAME_LMV, 0,
3824 /* Transfer default LMV striping from the parent */
3825 if (lds != NULL && lds->lds_dir_def_striping_set &&
3826 !LMVEA_DELETE_VALUES(lds->lds_dir_def_stripe_count,
3827 lds->lds_dir_def_stripe_offset)) {
3828 struct lmv_user_md_v1 *v1 = info->lti_ea_store;
3830 if (info->lti_ea_store_size < sizeof(*v1)) {
3831 rc = lod_ea_store_resize(info, sizeof(*v1));
3834 v1 = info->lti_ea_store;
3837 memset(v1, 0, sizeof(*v1));
3838 v1->lum_magic = cpu_to_le32(LMV_USER_MAGIC);
3839 v1->lum_stripe_count =
3840 cpu_to_le32(lds->lds_dir_def_stripe_count);
3841 v1->lum_stripe_offset =
3842 cpu_to_le32(lds->lds_dir_def_stripe_offset);
3844 cpu_to_le32(lds->lds_dir_def_hash_type);
3846 info->lti_buf.lb_buf = v1;
3847 info->lti_buf.lb_len = sizeof(*v1);
3849 rc = lod_dir_declare_xattr_set(env, dt, &info->lti_buf,
3850 XATTR_NAME_DEFAULT_LMV,
3853 rc = lod_xattr_set_default_lmv_on_dir(env, dt,
3855 XATTR_NAME_DEFAULT_LMV, 0,
3861 /* Transfer default LOV striping from the parent */
3862 if (lds != NULL && lds->lds_def_striping_set &&
3863 lds->lds_def_comp_cnt != 0) {
3864 struct lov_mds_md *lmm;
3865 int lmm_size = lod_comp_md_size(lo, true);
3867 if (info->lti_ea_store_size < lmm_size) {
3868 rc = lod_ea_store_resize(info, lmm_size);
3872 lmm = info->lti_ea_store;
3874 rc = lod_generate_lovea(env, lo, lmm, &lmm_size, true);
3878 info->lti_buf.lb_buf = lmm;
3879 info->lti_buf.lb_len = lmm_size;
3882 rc = lod_dir_declare_xattr_set(env, dt, &info->lti_buf,
3883 XATTR_NAME_LOV, 0, th);
3885 rc = lod_xattr_set_lov_on_dir(env, dt, &info->lti_buf,
3886 XATTR_NAME_LOV, 0, th);
3894 static int lod_declare_dir_striping_create(const struct lu_env *env,
3895 struct dt_object *dt,
3896 struct lu_attr *attr,
3898 struct dt_object_format *dof,
3901 return lod_dir_striping_create_internal(env, dt, attr, lmu, dof, th,
3905 static int lod_dir_striping_create(const struct lu_env *env,
3906 struct dt_object *dt,
3907 struct lu_attr *attr,
3908 struct dt_object_format *dof,
3911 return lod_dir_striping_create_internal(env, dt, attr, NULL, dof, th,
3916 * Make LOV EA for striped object.
3918 * Generate striping information and store it in the LOV EA of the given
3919 * object. The caller must ensure nobody else is calling the function
3920 * against the object concurrently. The transaction must be started.
3921 * FLDB service must be running as well; it's used to map FID to the target,
3922 * which is stored in LOV EA.
3924 * \param[in] env execution environment for this thread
3925 * \param[in] lo LOD object
3926 * \param[in] th transaction handle
3928 * \retval 0 if LOV EA is stored successfully
3929 * \retval negative error number on failure
3931 static int lod_generate_and_set_lovea(const struct lu_env *env,
3932 struct lod_object *lo,
3935 struct lod_thread_info *info = lod_env_info(env);
3936 struct dt_object *next = dt_object_child(&lo->ldo_obj);
3937 struct lov_mds_md_v1 *lmm;
3943 if (lo->ldo_comp_cnt == 0) {
3944 lod_striping_free(env, lo);
3945 rc = lod_sub_xattr_del(env, next, XATTR_NAME_LOV, th);
3949 lmm_size = lod_comp_md_size(lo, false);
3950 if (info->lti_ea_store_size < lmm_size) {
3951 rc = lod_ea_store_resize(info, lmm_size);
3955 lmm = info->lti_ea_store;
3957 rc = lod_generate_lovea(env, lo, lmm, &lmm_size, false);
3961 info->lti_buf.lb_buf = lmm;
3962 info->lti_buf.lb_len = lmm_size;
3963 rc = lod_sub_xattr_set(env, next, &info->lti_buf,
3964 XATTR_NAME_LOV, 0, th);
3969 * Delete layout component(s)
3971 * \param[in] env execution environment for this thread
3972 * \param[in] dt object
3973 * \param[in] th transaction handle
3975 * \retval 0 on success
3976 * \retval negative error number on failure
3978 static int lod_layout_del(const struct lu_env *env, struct dt_object *dt,
3981 struct lod_layout_component *lod_comp;
3982 struct lod_object *lo = lod_dt_obj(dt);
3983 struct dt_object *next = dt_object_child(dt);
3984 struct lu_attr *attr = &lod_env_info(env)->lti_attr;
3987 LASSERT(lo->ldo_is_composite);
3988 LASSERT(lo->ldo_comp_cnt > 0 && lo->ldo_comp_entries != NULL);
3990 left = lo->ldo_comp_cnt;
3991 for (i = (lo->ldo_comp_cnt - 1); i >= 0; i--) {
3992 lod_comp = &lo->ldo_comp_entries[i];
3994 if (lod_comp->llc_id != LCME_ID_INVAL)
3998 /* Not instantiated component */
3999 if (lod_comp->llc_stripe == NULL)
4002 LASSERT(lod_comp->llc_stripe_count > 0);
4003 for (j = 0; j < lod_comp->llc_stripe_count; j++) {
4004 struct dt_object *obj = lod_comp->llc_stripe[j];
4008 rc = lod_sub_destroy(env, obj, th);
4012 lu_object_put(env, &obj->do_lu);
4013 lod_comp->llc_stripe[j] = NULL;
4015 OBD_FREE(lod_comp->llc_stripe, sizeof(struct dt_object *) *
4016 lod_comp->llc_stripes_allocated);
4017 lod_comp->llc_stripe = NULL;
4018 OBD_FREE(lod_comp->llc_ost_indices,
4019 sizeof(__u32) * lod_comp->llc_stripes_allocated);
4020 lod_comp->llc_ost_indices = NULL;
4021 lod_comp->llc_stripes_allocated = 0;
4022 lod_obj_set_pool(lo, i, NULL);
4023 if (lod_comp->llc_ostlist.op_array) {
4024 OBD_FREE(lod_comp->llc_ostlist.op_array,
4025 lod_comp->llc_ostlist.op_size);
4026 lod_comp->llc_ostlist.op_array = NULL;
4027 lod_comp->llc_ostlist.op_size = 0;
4031 LASSERTF(left >= 0 && left < lo->ldo_comp_cnt, "left = %d\n", left);
4033 struct lod_layout_component *comp_array;
4035 OBD_ALLOC(comp_array, sizeof(*comp_array) * left);
4036 if (comp_array == NULL)
4037 GOTO(out, rc = -ENOMEM);
4039 memcpy(&comp_array[0], &lo->ldo_comp_entries[0],
4040 sizeof(*comp_array) * left);
4042 OBD_FREE(lo->ldo_comp_entries,
4043 sizeof(*comp_array) * lo->ldo_comp_cnt);
4044 lo->ldo_comp_entries = comp_array;
4045 lo->ldo_comp_cnt = left;
4047 LASSERT(lo->ldo_mirror_count == 1);
4048 lo->ldo_mirrors[0].lme_end = left - 1;
4049 lod_obj_inc_layout_gen(lo);
4051 lod_free_comp_entries(lo);
4054 LASSERT(dt_object_exists(dt));
4055 rc = dt_attr_get(env, next, attr);
4059 if (attr->la_size > 0) {
4061 attr->la_valid = LA_SIZE;
4062 rc = lod_sub_attr_set(env, next, attr, th);
4067 rc = lod_generate_and_set_lovea(env, lo, th);
4071 lod_striping_free(env, lo);
4076 static int lod_get_default_lov_striping(const struct lu_env *env,
4077 struct lod_object *lo,
4078 struct lod_default_striping *lds);
4080 * Implementation of dt_object_operations::do_xattr_set.
4082 * Sets specified extended attribute on the object. Three types of EAs are
4084 * LOV EA - stores striping for a regular file or default striping (when set
4086 * LMV EA - stores a marker for the striped directories
4087 * DMV EA - stores default directory striping
4089 * When striping is applied to a non-striped existing object (this is called
4090 * late striping), then LOD notices the caller wants to turn the object into a
4091 * striped one. The stripe objects are created and appropriate EA is set:
4092 * LOV EA storing all the stripes directly or LMV EA storing just a small header
4093 * with striping configuration.
4095 * \see dt_object_operations::do_xattr_set() in the API description for details.
4097 static int lod_xattr_set(const struct lu_env *env,
4098 struct dt_object *dt, const struct lu_buf *buf,
4099 const char *name, int fl, struct thandle *th)
4101 struct dt_object *next = dt_object_child(dt);
4105 if (S_ISDIR(dt->do_lu.lo_header->loh_attr) &&
4106 strcmp(name, XATTR_NAME_LMV) == 0) {
4107 rc = lod_dir_striping_create(env, dt, NULL, NULL, th);
4109 } else if (S_ISDIR(dt->do_lu.lo_header->loh_attr) &&
4110 strncmp(name, XATTR_NAME_LMV, strlen(XATTR_NAME_LMV)) == 0 &&
4111 strlen(name) > strlen(XATTR_NAME_LMV) + 1) {
4112 const char *op = name + strlen(XATTR_NAME_LMV) + 1;
4116 * XATTR_NAME_LMV".add" is never called, but only declared,
4117 * because lod_xattr_set_lmv() will do the addition.
4119 if (strcmp(op, "del") == 0)
4120 rc = lod_dir_layout_delete(env, dt, buf, th);
4121 else if (strcmp(op, "set") == 0)
4122 rc = lod_sub_xattr_set(env, next, buf, XATTR_NAME_LMV,
4126 } else if (S_ISDIR(dt->do_lu.lo_header->loh_attr) &&
4127 strcmp(name, XATTR_NAME_LOV) == 0) {
4128 struct lod_default_striping *lds = lod_lds_buf_get(env);
4129 struct lov_user_md_v1 *v1 = buf->lb_buf;
4130 char pool[LOV_MAXPOOLNAME + 1];
4133 /* get existing striping config */
4134 rc = lod_get_default_lov_striping(env, lod_dt_obj(dt), lds);
4138 memset(pool, 0, sizeof(pool));
4139 if (lds->lds_def_striping_set == 1)
4140 lod_layout_get_pool(lds->lds_def_comp_entries,
4141 lds->lds_def_comp_cnt, pool,
4144 is_del = LOVEA_DELETE_VALUES(v1->lmm_stripe_size,
4145 v1->lmm_stripe_count,
4146 v1->lmm_stripe_offset,
4149 /* Retain the pool name if it is not given */
4150 if (v1->lmm_magic == LOV_USER_MAGIC_V1 && pool[0] != '\0' &&
4152 struct lod_thread_info *info = lod_env_info(env);
4153 struct lov_user_md_v3 *v3 = info->lti_ea_store;
4155 memset(v3, 0, sizeof(*v3));
4156 v3->lmm_magic = cpu_to_le32(LOV_USER_MAGIC_V3);
4157 v3->lmm_pattern = cpu_to_le32(v1->lmm_pattern);
4158 v3->lmm_stripe_count =
4159 cpu_to_le32(v1->lmm_stripe_count);
4160 v3->lmm_stripe_offset =
4161 cpu_to_le32(v1->lmm_stripe_offset);
4162 v3->lmm_stripe_size = cpu_to_le32(v1->lmm_stripe_size);
4164 strlcpy(v3->lmm_pool_name, pool,
4165 sizeof(v3->lmm_pool_name));
4167 info->lti_buf.lb_buf = v3;
4168 info->lti_buf.lb_len = sizeof(*v3);
4169 rc = lod_xattr_set_lov_on_dir(env, dt, &info->lti_buf,
4172 rc = lod_xattr_set_lov_on_dir(env, dt, buf, name,
4176 if (lds->lds_def_striping_set == 1 &&
4177 lds->lds_def_comp_entries != NULL)
4178 lod_free_def_comp_entries(lds);
4181 } else if (S_ISDIR(dt->do_lu.lo_header->loh_attr) &&
4182 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0) {
4184 rc = lod_xattr_set_default_lmv_on_dir(env, dt, buf, name, fl,
4187 } else if (S_ISREG(dt->do_lu.lo_header->loh_attr) &&
4188 (!strcmp(name, XATTR_NAME_LOV) ||
4189 !strncmp(name, XATTR_LUSTRE_LOV,
4190 strlen(XATTR_LUSTRE_LOV)))) {
4191 /* in case of lov EA swap, just set it
4192 * if not, it is a replay so check striping match what we
4193 * already have during req replay, declare_xattr_set()
4194 * defines striping, then create() does the work */
4195 if (fl & LU_XATTR_REPLACE) {
4196 /* free stripes, then update disk */
4197 lod_striping_free(env, lod_dt_obj(dt));
4199 rc = lod_sub_xattr_set(env, next, buf, name, fl, th);
4200 } else if (dt_object_remote(dt)) {
4201 /* This only happens during migration, see
4202 * mdd_migrate_create(), in which Master MDT will
4203 * create a remote target object, and only set
4204 * (migrating) stripe EA on the remote object,
4205 * and does not need creating each stripes. */
4206 rc = lod_sub_xattr_set(env, next, buf, name,
4208 } else if (strcmp(name, XATTR_LUSTRE_LOV".del") == 0) {
4209 /* delete component(s) */
4210 LASSERT(lod_dt_obj(dt)->ldo_comp_cached);
4211 rc = lod_layout_del(env, dt, th);
4214 * When 'name' is XATTR_LUSTRE_LOV or XATTR_NAME_LOV,
4215 * it's going to create create file with specified
4216 * component(s), the striping must have not being
4217 * cached in this case;
4219 * Otherwise, it's going to add/change component(s) to
4220 * an existing file, the striping must have been cached
4223 LASSERT(equi(!strcmp(name, XATTR_LUSTRE_LOV) ||
4224 !strcmp(name, XATTR_NAME_LOV),
4225 !lod_dt_obj(dt)->ldo_comp_cached));
4227 rc = lod_striped_create(env, dt, NULL, NULL, th);
4230 } else if (strcmp(name, XATTR_NAME_FID) == 0) {
4231 rc = lod_replace_parent_fid(env, dt, buf, th, false);
4236 /* then all other xattr */
4237 rc = lod_xattr_set_internal(env, dt, buf, name, fl, th);
4243 * Implementation of dt_object_operations::do_declare_xattr_del.
4245 * \see dt_object_operations::do_declare_xattr_del() in the API description
4248 static int lod_declare_xattr_del(const struct lu_env *env,
4249 struct dt_object *dt, const char *name,
4252 struct lod_object *lo = lod_dt_obj(dt);
4253 struct dt_object *next = dt_object_child(dt);
4258 rc = lod_sub_declare_xattr_del(env, next, name, th);
4262 if (!S_ISDIR(dt->do_lu.lo_header->loh_attr))
4265 /* set xattr to each stripes, if needed */
4266 rc = lod_striping_load(env, lo);
4270 if (lo->ldo_dir_stripe_count == 0)
4273 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
4274 struct dt_object *dto = lo->ldo_stripe[i];
4277 rc = lod_sub_declare_xattr_del(env, dto, name, th);
4286 * Implementation of dt_object_operations::do_xattr_del.
4288 * If EA storing a regular striping is being deleted, then release
4289 * all the references to the stripe objects in core.
4291 * \see dt_object_operations::do_xattr_del() in the API description for details.
4293 static int lod_xattr_del(const struct lu_env *env, struct dt_object *dt,
4294 const char *name, struct thandle *th)
4296 struct dt_object *next = dt_object_child(dt);
4297 struct lod_object *lo = lod_dt_obj(dt);
4302 if (!strcmp(name, XATTR_NAME_LOV) || !strcmp(name, XATTR_NAME_LMV))
4303 lod_striping_free(env, lod_dt_obj(dt));
4305 rc = lod_sub_xattr_del(env, next, name, th);
4306 if (rc != 0 || !S_ISDIR(dt->do_lu.lo_header->loh_attr))
4309 if (lo->ldo_dir_stripe_count == 0)
4312 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
4313 struct dt_object *dto = lo->ldo_stripe[i];
4317 rc = lod_sub_xattr_del(env, dto, name, th);
4326 * Implementation of dt_object_operations::do_xattr_list.
4328 * \see dt_object_operations::do_xattr_list() in the API description
4331 static int lod_xattr_list(const struct lu_env *env,
4332 struct dt_object *dt, const struct lu_buf *buf)
4334 return dt_xattr_list(env, dt_object_child(dt), buf);
4337 static inline int lod_object_will_be_striped(int is_reg, const struct lu_fid *fid)
4339 return (is_reg && fid_seq(fid) != FID_SEQ_LOCAL_FILE);
4343 * Copy OST list from layout provided by user.
4345 * \param[in] lod_comp layout_component to be filled
4346 * \param[in] v3 LOV EA V3 user data
4348 * \retval 0 on success
4349 * \retval negative if failed
4351 int lod_comp_copy_ost_lists(struct lod_layout_component *lod_comp,
4352 struct lov_user_md_v3 *v3)
4358 if (v3->lmm_stripe_offset == LOV_OFFSET_DEFAULT)
4359 v3->lmm_stripe_offset = v3->lmm_objects[0].l_ost_idx;
4361 if (lod_comp->llc_ostlist.op_array) {
4362 if (lod_comp->llc_ostlist.op_size >=
4363 v3->lmm_stripe_count * sizeof(__u32)) {
4364 lod_comp->llc_ostlist.op_count =
4365 v3->lmm_stripe_count;
4368 OBD_FREE(lod_comp->llc_ostlist.op_array,
4369 lod_comp->llc_ostlist.op_size);
4372 /* copy ost list from lmm */
4373 lod_comp->llc_ostlist.op_count = v3->lmm_stripe_count;
4374 lod_comp->llc_ostlist.op_size = v3->lmm_stripe_count * sizeof(__u32);
4375 OBD_ALLOC(lod_comp->llc_ostlist.op_array,
4376 lod_comp->llc_ostlist.op_size);
4377 if (!lod_comp->llc_ostlist.op_array)
4380 for (j = 0; j < v3->lmm_stripe_count; j++) {
4381 lod_comp->llc_ostlist.op_array[j] =
4382 v3->lmm_objects[j].l_ost_idx;
4390 * Get default striping.
4392 * \param[in] env execution environment
4393 * \param[in] lo object
4394 * \param[out] lds default striping
4396 * \retval 0 on success
4397 * \retval negative if failed
4399 static int lod_get_default_lov_striping(const struct lu_env *env,
4400 struct lod_object *lo,
4401 struct lod_default_striping *lds)
4403 struct lod_thread_info *info = lod_env_info(env);
4404 struct lov_user_md_v1 *v1 = NULL;
4405 struct lov_user_md_v3 *v3 = NULL;
4406 struct lov_comp_md_v1 *comp_v1 = NULL;
4413 lds->lds_def_striping_set = 0;
4415 rc = lod_get_lov_ea(env, lo);
4419 if (rc < (typeof(rc))sizeof(struct lov_user_md))
4422 v1 = info->lti_ea_store;
4423 if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
4424 lustre_swab_lov_user_md_v1(v1);
4425 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
4426 v3 = (struct lov_user_md_v3 *)v1;
4427 lustre_swab_lov_user_md_v3(v3);
4428 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_SPECIFIC)) {
4429 v3 = (struct lov_user_md_v3 *)v1;
4430 lustre_swab_lov_user_md_v3(v3);
4431 lustre_swab_lov_user_md_objects(v3->lmm_objects,
4432 v3->lmm_stripe_count);
4433 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_COMP_V1)) {
4434 comp_v1 = (struct lov_comp_md_v1 *)v1;
4435 lustre_swab_lov_comp_md_v1(comp_v1);
4438 if (v1->lmm_magic != LOV_MAGIC_V3 && v1->lmm_magic != LOV_MAGIC_V1 &&
4439 v1->lmm_magic != LOV_MAGIC_COMP_V1 &&
4440 v1->lmm_magic != LOV_USER_MAGIC_SPECIFIC)
4443 if (v1->lmm_magic == LOV_MAGIC_COMP_V1) {
4444 comp_v1 = (struct lov_comp_md_v1 *)v1;
4445 comp_cnt = comp_v1->lcm_entry_count;
4448 mirror_cnt = comp_v1->lcm_mirror_count + 1;
4456 /* realloc default comp entries if necessary */
4457 rc = lod_def_striping_comp_resize(lds, comp_cnt);
4461 lds->lds_def_comp_cnt = comp_cnt;
4462 lds->lds_def_striping_is_composite = composite;
4463 lds->lds_def_mirror_cnt = mirror_cnt;
4465 for (i = 0; i < comp_cnt; i++) {
4466 struct lod_layout_component *lod_comp;
4469 lod_comp = &lds->lds_def_comp_entries[i];
4471 * reset lod_comp values, llc_stripes is always NULL in
4472 * the default striping template, llc_pool will be reset
4475 memset(lod_comp, 0, offsetof(typeof(*lod_comp), llc_pool));
4478 v1 = (struct lov_user_md *)((char *)comp_v1 +
4479 comp_v1->lcm_entries[i].lcme_offset);
4480 lod_comp->llc_extent =
4481 comp_v1->lcm_entries[i].lcme_extent;
4482 /* We only inherit certain flags from the layout */
4483 lod_comp->llc_flags =
4484 comp_v1->lcm_entries[i].lcme_flags &
4485 LCME_TEMPLATE_FLAGS;
4488 if (v1->lmm_pattern != LOV_PATTERN_RAID0 &&
4489 v1->lmm_pattern != LOV_PATTERN_MDT &&
4490 v1->lmm_pattern != 0) {
4491 lod_free_def_comp_entries(lds);
4495 CDEBUG(D_LAYOUT, DFID" stripe_count=%d stripe_size=%d "
4496 "stripe_offset=%d\n",
4497 PFID(lu_object_fid(&lo->ldo_obj.do_lu)),
4498 (int)v1->lmm_stripe_count, (int)v1->lmm_stripe_size,
4499 (int)v1->lmm_stripe_offset);
4501 lod_comp->llc_stripe_count = v1->lmm_stripe_count;
4502 lod_comp->llc_stripe_size = v1->lmm_stripe_size;
4503 lod_comp->llc_stripe_offset = v1->lmm_stripe_offset;
4504 lod_comp->llc_pattern = v1->lmm_pattern;
4507 if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
4508 /* XXX: sanity check here */
4509 v3 = (struct lov_user_md_v3 *) v1;
4510 if (v3->lmm_pool_name[0] != '\0')
4511 pool = v3->lmm_pool_name;
4513 lod_set_def_pool(lds, i, pool);
4514 if (v1->lmm_magic == LOV_USER_MAGIC_SPECIFIC) {
4515 v3 = (struct lov_user_md_v3 *)v1;
4516 rc = lod_comp_copy_ost_lists(lod_comp, v3);
4519 } else if (lod_comp->llc_ostlist.op_array &&
4520 lod_comp->llc_ostlist.op_count) {
4521 for (j = 0; j < lod_comp->llc_ostlist.op_count; j++)
4522 lod_comp->llc_ostlist.op_array[j] = -1;
4523 lod_comp->llc_ostlist.op_count = 0;
4527 lds->lds_def_striping_set = 1;
4532 * Get default directory striping.
4534 * \param[in] env execution environment
4535 * \param[in] lo object
4536 * \param[out] lds default striping
4538 * \retval 0 on success
4539 * \retval negative if failed
4541 static int lod_get_default_lmv_striping(const struct lu_env *env,
4542 struct lod_object *lo,
4543 struct lod_default_striping *lds)
4545 struct lod_thread_info *info = lod_env_info(env);
4546 struct lmv_user_md_v1 *v1 = NULL;
4550 lds->lds_dir_def_striping_set = 0;
4551 rc = lod_get_default_lmv_ea(env, lo);
4555 if (rc < (typeof(rc))sizeof(struct lmv_user_md))
4558 v1 = info->lti_ea_store;
4560 lds->lds_dir_def_stripe_count = le32_to_cpu(v1->lum_stripe_count);
4561 lds->lds_dir_def_stripe_offset = le32_to_cpu(v1->lum_stripe_offset);
4562 lds->lds_dir_def_hash_type = le32_to_cpu(v1->lum_hash_type);
4563 lds->lds_dir_def_striping_set = 1;
4569 * Get default striping in the object.
4571 * Get object default striping and default directory striping.
4573 * \param[in] env execution environment
4574 * \param[in] lo object
4575 * \param[out] lds default striping
4577 * \retval 0 on success
4578 * \retval negative if failed
4580 static int lod_get_default_striping(const struct lu_env *env,
4581 struct lod_object *lo,
4582 struct lod_default_striping *lds)
4586 rc = lod_get_default_lov_striping(env, lo, lds);
4587 rc1 = lod_get_default_lmv_striping(env, lo, lds);
4588 if (rc == 0 && rc1 < 0)
4595 * Apply default striping on object.
4597 * If object striping pattern is not set, set to the one in default striping.
4598 * The default striping is from parent or fs.
4600 * \param[in] lo new object
4601 * \param[in] lds default striping
4602 * \param[in] mode new object's mode
4604 static void lod_striping_from_default(struct lod_object *lo,
4605 const struct lod_default_striping *lds,
4608 struct lod_device *d = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
4609 struct lov_desc *desc = &d->lod_desc;
4612 if (lds->lds_def_striping_set && S_ISREG(mode)) {
4613 rc = lod_alloc_comp_entries(lo, lds->lds_def_mirror_cnt,
4614 lds->lds_def_comp_cnt);
4618 lo->ldo_is_composite = lds->lds_def_striping_is_composite;
4619 if (lds->lds_def_mirror_cnt > 1)
4620 lo->ldo_flr_state = LCM_FL_RDONLY;
4622 for (i = 0; i < lo->ldo_comp_cnt; i++) {
4623 struct lod_layout_component *obj_comp =
4624 &lo->ldo_comp_entries[i];
4625 struct lod_layout_component *def_comp =
4626 &lds->lds_def_comp_entries[i];
4628 CDEBUG(D_LAYOUT, "Inherit from default: flags=%#x "
4629 "size=%hu nr=%u offset=%u pattern=%#x pool=%s\n",
4630 def_comp->llc_flags,
4631 def_comp->llc_stripe_size,
4632 def_comp->llc_stripe_count,
4633 def_comp->llc_stripe_offset,
4634 def_comp->llc_pattern,
4635 def_comp->llc_pool ?: "");
4637 *obj_comp = *def_comp;
4638 if (def_comp->llc_pool != NULL) {
4639 /* pointer was copied from def_comp */
4640 obj_comp->llc_pool = NULL;
4641 lod_obj_set_pool(lo, i, def_comp->llc_pool);
4645 if (def_comp->llc_ostlist.op_array &&
4646 def_comp->llc_ostlist.op_count) {
4647 OBD_ALLOC(obj_comp->llc_ostlist.op_array,
4648 obj_comp->llc_ostlist.op_size);
4649 if (!obj_comp->llc_ostlist.op_array)
4651 memcpy(obj_comp->llc_ostlist.op_array,
4652 def_comp->llc_ostlist.op_array,
4653 obj_comp->llc_ostlist.op_size);
4654 } else if (def_comp->llc_ostlist.op_array) {
4655 obj_comp->llc_ostlist.op_array = NULL;
4659 * Don't initialize these fields for plain layout
4660 * (v1/v3) here, they are inherited in the order of
4661 * 'parent' -> 'fs default (root)' -> 'global default
4662 * values for stripe_count & stripe_size'.
4664 * see lod_ah_init().
4666 if (!lo->ldo_is_composite)
4669 lod_adjust_stripe_info(obj_comp, desc);
4671 } else if (lds->lds_dir_def_striping_set && S_ISDIR(mode)) {
4672 if (lo->ldo_dir_stripe_count == 0)
4673 lo->ldo_dir_stripe_count =
4674 lds->lds_dir_def_stripe_count;
4675 if (lo->ldo_dir_stripe_offset == -1)
4676 lo->ldo_dir_stripe_offset =
4677 lds->lds_dir_def_stripe_offset;
4678 if (lo->ldo_dir_hash_type == 0)
4679 lo->ldo_dir_hash_type = lds->lds_dir_def_hash_type;
4681 CDEBUG(D_LAYOUT, "striping from default dir: count:%hu, "
4682 "offset:%u, hash_type:%u\n",
4683 lo->ldo_dir_stripe_count, lo->ldo_dir_stripe_offset,
4684 lo->ldo_dir_hash_type);
4688 static inline bool lod_need_inherit_more(struct lod_object *lo, bool from_root)
4690 struct lod_layout_component *lod_comp;
4692 if (lo->ldo_comp_cnt == 0)
4695 if (lo->ldo_is_composite)
4698 lod_comp = &lo->ldo_comp_entries[0];
4700 if (lod_comp->llc_stripe_count <= 0 ||
4701 lod_comp->llc_stripe_size <= 0)
4704 if (from_root && (lod_comp->llc_pool == NULL ||
4705 lod_comp->llc_stripe_offset == LOV_OFFSET_DEFAULT))
4712 * Implementation of dt_object_operations::do_ah_init.
4714 * This method is used to make a decision on the striping configuration for the
4715 * object being created. It can be taken from the \a parent object if it exists,
4716 * or filesystem's default. The resulting configuration (number of stripes,
4717 * stripe size/offset, pool name, etc) is stored in the object itself and will
4718 * be used by the methods like ->doo_declare_create().
4720 * \see dt_object_operations::do_ah_init() in the API description for details.
4722 static void lod_ah_init(const struct lu_env *env,
4723 struct dt_allocation_hint *ah,
4724 struct dt_object *parent,
4725 struct dt_object *child,
4728 struct lod_device *d = lu2lod_dev(child->do_lu.lo_dev);
4729 struct lod_thread_info *info = lod_env_info(env);
4730 struct lod_default_striping *lds = lod_lds_buf_get(env);
4731 struct dt_object *nextp = NULL;
4732 struct dt_object *nextc;
4733 struct lod_object *lp = NULL;
4734 struct lod_object *lc;
4735 struct lov_desc *desc;
4736 struct lod_layout_component *lod_comp;
4742 if (likely(parent)) {
4743 nextp = dt_object_child(parent);
4744 lp = lod_dt_obj(parent);
4747 nextc = dt_object_child(child);
4748 lc = lod_dt_obj(child);
4750 LASSERT(!lod_obj_is_striped(child));
4751 /* default layout template may have been set on the regular file
4752 * when this is called from mdd_create_data() */
4753 if (S_ISREG(child_mode))
4754 lod_free_comp_entries(lc);
4756 if (!dt_object_exists(nextc))
4757 nextc->do_ops->do_ah_init(env, ah, nextp, nextc, child_mode);
4759 if (S_ISDIR(child_mode)) {
4760 const struct lmv_user_md_v1 *lum1 = ah->dah_eadata;
4762 /* other default values are 0 */
4763 lc->ldo_dir_stripe_offset = -1;
4766 * If parent object is not root directory,
4767 * then get default striping from parent object.
4769 if (likely(lp != NULL) && !fid_is_root(lod_object_fid(lp)))
4770 lod_get_default_striping(env, lp, lds);
4772 /* set child default striping info, default value is NULL */
4773 if (lds->lds_def_striping_set || lds->lds_dir_def_striping_set)
4774 lc->ldo_def_striping = lds;
4776 /* It should always honour the specified stripes */
4777 /* Note: old client (< 2.7)might also do lfs mkdir, whose EA
4778 * will have old magic. In this case, we should ignore the
4779 * stripe count and try to create dir by default stripe.
4781 if (ah->dah_eadata != NULL && ah->dah_eadata_len != 0 &&
4782 (le32_to_cpu(lum1->lum_magic) == LMV_USER_MAGIC ||
4783 le32_to_cpu(lum1->lum_magic) == LMV_USER_MAGIC_SPECIFIC)) {
4784 lc->ldo_dir_stripe_count =
4785 le32_to_cpu(lum1->lum_stripe_count);
4786 lc->ldo_dir_stripe_offset =
4787 le32_to_cpu(lum1->lum_stripe_offset);
4788 lc->ldo_dir_hash_type =
4789 le32_to_cpu(lum1->lum_hash_type);
4791 "set dirstripe: count %hu, offset %d, hash %u\n",
4792 lc->ldo_dir_stripe_count,
4793 (int)lc->ldo_dir_stripe_offset,
4794 lc->ldo_dir_hash_type);
4796 /* transfer defaults LMV to new directory */
4797 lod_striping_from_default(lc, lds, child_mode);
4799 /* set count 0 to create normal directory */
4800 if (lc->ldo_dir_stripe_count == 1)
4801 lc->ldo_dir_stripe_count = 0;
4804 /* shrink the stripe_count to the avaible MDT count */
4805 if (lc->ldo_dir_stripe_count > d->lod_remote_mdt_count + 1 &&
4806 !OBD_FAIL_CHECK(OBD_FAIL_LARGE_STRIPE)) {
4807 lc->ldo_dir_stripe_count = d->lod_remote_mdt_count + 1;
4808 if (lc->ldo_dir_stripe_count == 1)
4809 lc->ldo_dir_stripe_count = 0;
4812 CDEBUG(D_INFO, "final dir stripe [%hu %d %u]\n",
4813 lc->ldo_dir_stripe_count,
4814 (int)lc->ldo_dir_stripe_offset, lc->ldo_dir_hash_type);
4819 /* child object regular file*/
4821 if (!lod_object_will_be_striped(S_ISREG(child_mode),
4822 lu_object_fid(&child->do_lu)))
4825 /* If object is going to be striped over OSTs, transfer default
4826 * striping information to the child, so that we can use it
4827 * during declaration and creation.
4829 * Try from the parent first.
4831 if (likely(lp != NULL)) {
4832 rc = lod_get_default_lov_striping(env, lp, lds);
4834 lod_striping_from_default(lc, lds, child_mode);
4837 /* Initialize lod_device::lod_md_root object reference */
4838 if (d->lod_md_root == NULL) {
4839 struct dt_object *root;
4840 struct lod_object *lroot;
4842 lu_root_fid(&info->lti_fid);
4843 root = dt_locate(env, &d->lod_dt_dev, &info->lti_fid);
4844 if (!IS_ERR(root)) {
4845 lroot = lod_dt_obj(root);
4847 spin_lock(&d->lod_lock);
4848 if (d->lod_md_root != NULL)
4849 dt_object_put(env, &d->lod_md_root->ldo_obj);
4850 d->lod_md_root = lroot;
4851 spin_unlock(&d->lod_lock);
4855 /* try inherit layout from the root object (fs default) when:
4856 * - parent does not have default layout; or
4857 * - parent has plain(v1/v3) default layout, and some attributes
4858 * are not specified in the default layout;
4860 if (d->lod_md_root != NULL && lod_need_inherit_more(lc, true)) {
4861 rc = lod_get_default_lov_striping(env, d->lod_md_root, lds);
4864 if (lc->ldo_comp_cnt == 0) {
4865 lod_striping_from_default(lc, lds, child_mode);
4866 } else if (!lds->lds_def_striping_is_composite) {
4867 struct lod_layout_component *def_comp;
4869 LASSERT(!lc->ldo_is_composite);
4870 lod_comp = &lc->ldo_comp_entries[0];
4871 def_comp = &lds->lds_def_comp_entries[0];
4873 if (lod_comp->llc_stripe_count <= 0)
4874 lod_comp->llc_stripe_count =
4875 def_comp->llc_stripe_count;
4876 if (lod_comp->llc_stripe_size <= 0)
4877 lod_comp->llc_stripe_size =
4878 def_comp->llc_stripe_size;
4879 if (lod_comp->llc_stripe_offset == LOV_OFFSET_DEFAULT)
4880 lod_comp->llc_stripe_offset =
4881 def_comp->llc_stripe_offset;
4882 if (lod_comp->llc_pool == NULL)
4883 lod_obj_set_pool(lc, 0, def_comp->llc_pool);
4888 * fs default striping may not be explicitly set, or historically set
4889 * in config log, use them.
4891 if (lod_need_inherit_more(lc, false)) {
4892 if (lc->ldo_comp_cnt == 0) {
4893 rc = lod_alloc_comp_entries(lc, 0, 1);
4895 /* fail to allocate memory, will create a
4896 * non-striped file. */
4898 lc->ldo_is_composite = 0;
4899 lod_comp = &lc->ldo_comp_entries[0];
4900 lod_comp->llc_stripe_offset = LOV_OFFSET_DEFAULT;
4902 LASSERT(!lc->ldo_is_composite);
4903 lod_comp = &lc->ldo_comp_entries[0];
4904 desc = &d->lod_desc;
4905 lod_adjust_stripe_info(lod_comp, desc);
4911 #define ll_do_div64(aaa,bbb) do_div((aaa), (bbb))
4913 * Size initialization on late striping.
4915 * Propagate the size of a truncated object to a deferred striping.
4916 * This function handles a special case when truncate was done on a
4917 * non-striped object and now while the striping is being created
4918 * we can't lose that size, so we have to propagate it to the stripes
4921 * \param[in] env execution environment
4922 * \param[in] dt object
4923 * \param[in] th transaction handle
4925 * \retval 0 on success
4926 * \retval negative if failed
4928 static int lod_declare_init_size(const struct lu_env *env,
4929 struct dt_object *dt, struct thandle *th)
4931 struct dt_object *next = dt_object_child(dt);
4932 struct lod_object *lo = lod_dt_obj(dt);
4933 struct dt_object **objects = NULL;
4934 struct lu_attr *attr = &lod_env_info(env)->lti_attr;
4935 uint64_t size, offs;
4936 int i, rc, stripe, stripe_count = 0, stripe_size = 0;
4937 struct lu_extent size_ext;
4940 if (!lod_obj_is_striped(dt))
4943 rc = dt_attr_get(env, next, attr);
4944 LASSERT(attr->la_valid & LA_SIZE);
4948 size = attr->la_size;
4952 size_ext = (typeof(size_ext)){ .e_start = size - 1, .e_end = size };
4953 for (i = 0; i < lo->ldo_comp_cnt; i++) {
4954 struct lod_layout_component *lod_comp;
4955 struct lu_extent *extent;
4957 lod_comp = &lo->ldo_comp_entries[i];
4959 if (lod_comp->llc_stripe == NULL)
4962 extent = &lod_comp->llc_extent;
4963 CDEBUG(D_INFO, "%lld "DEXT"\n", size, PEXT(extent));
4964 if (!lo->ldo_is_composite ||
4965 lu_extent_is_overlapped(extent, &size_ext)) {
4966 objects = lod_comp->llc_stripe;
4967 stripe_count = lod_comp->llc_stripe_count;
4968 stripe_size = lod_comp->llc_stripe_size;
4971 if (stripe_count == 0)
4974 LASSERT(objects != NULL && stripe_size != 0);
4975 /* ll_do_div64(a, b) returns a % b, and a = a / b */
4976 ll_do_div64(size, (__u64)stripe_size);
4977 stripe = ll_do_div64(size, (__u64)stripe_count);
4978 LASSERT(objects[stripe] != NULL);
4980 size = size * stripe_size;
4981 offs = attr->la_size;
4982 size += ll_do_div64(offs, stripe_size);
4984 attr->la_valid = LA_SIZE;
4985 attr->la_size = size;
4987 rc = lod_sub_declare_attr_set(env, objects[stripe],
4996 * Declare creation of striped object.
4998 * The function declares creation stripes for a regular object. The function
4999 * also declares whether the stripes will be created with non-zero size if
5000 * previously size was set non-zero on the master object. If object \a dt is
5001 * not local, then only fully defined striping can be applied in \a lovea.
5002 * Otherwise \a lovea can be in the form of pattern, see lod_qos_parse_config()
5005 * \param[in] env execution environment
5006 * \param[in] dt object
5007 * \param[in] attr attributes the stripes will be created with
5008 * \param[in] lovea a buffer containing striping description
5009 * \param[in] th transaction handle
5011 * \retval 0 on success
5012 * \retval negative if failed
5014 int lod_declare_striped_create(const struct lu_env *env, struct dt_object *dt,
5015 struct lu_attr *attr,
5016 const struct lu_buf *lovea, struct thandle *th)
5018 struct lod_thread_info *info = lod_env_info(env);
5019 struct dt_object *next = dt_object_child(dt);
5020 struct lod_object *lo = lod_dt_obj(dt);
5024 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_ALLOC_OBDO))
5025 GOTO(out, rc = -ENOMEM);
5027 if (!dt_object_remote(next)) {
5028 /* choose OST and generate appropriate objects */
5029 rc = lod_prepare_create(env, lo, attr, lovea, th);
5034 * declare storage for striping data
5036 info->lti_buf.lb_len = lod_comp_md_size(lo, false);
5038 /* LOD can not choose OST objects for remote objects, i.e.
5039 * stripes must be ready before that. Right now, it can only
5040 * happen during migrate, i.e. migrate process needs to create
5041 * remote regular file (mdd_migrate_create), then the migrate
5042 * process will provide stripeEA. */
5043 LASSERT(lovea != NULL);
5044 info->lti_buf = *lovea;
5047 rc = lod_sub_declare_xattr_set(env, next, &info->lti_buf,
5048 XATTR_NAME_LOV, 0, th);
5053 * if striping is created with local object's size > 0,
5054 * we have to propagate this size to specific object
5055 * the case is possible only when local object was created previously
5057 if (dt_object_exists(next))
5058 rc = lod_declare_init_size(env, dt, th);
5061 /* failed to create striping or to set initial size, let's reset
5062 * config so that others don't get confused */
5064 lod_striping_free(env, lo);
5070 * Implementation of dt_object_operations::do_declare_create.
5072 * The method declares creation of a new object. If the object will be striped,
5073 * then helper functions are called to find FIDs for the stripes, declare
5074 * creation of the stripes and declare initialization of the striping
5075 * information to be stored in the master object.
5077 * \see dt_object_operations::do_declare_create() in the API description
5080 static int lod_declare_create(const struct lu_env *env, struct dt_object *dt,
5081 struct lu_attr *attr,
5082 struct dt_allocation_hint *hint,
5083 struct dt_object_format *dof, struct thandle *th)
5085 struct dt_object *next = dt_object_child(dt);
5086 struct lod_object *lo = lod_dt_obj(dt);
5095 * first of all, we declare creation of local object
5097 rc = lod_sub_declare_create(env, next, attr, hint, dof, th);
5102 * it's lod_ah_init() that has decided the object will be striped
5104 if (dof->dof_type == DFT_REGULAR) {
5105 /* callers don't want stripes */
5106 /* XXX: all tricky interactions with ->ah_make_hint() decided
5107 * to use striping, then ->declare_create() behaving differently
5108 * should be cleaned */
5109 if (dof->u.dof_reg.striped != 0)
5110 rc = lod_declare_striped_create(env, dt, attr,
5112 } else if (dof->dof_type == DFT_DIR) {
5113 struct seq_server_site *ss;
5114 struct lu_buf buf = { NULL };
5115 struct lu_buf *lmu = NULL;
5117 ss = lu_site2seq(dt->do_lu.lo_dev->ld_site);
5119 /* If the parent has default stripeEA, and client
5120 * did not find it before sending create request,
5121 * then MDT will return -EREMOTE, and client will
5122 * retrieve the default stripeEA and re-create the
5125 * Note: if dah_eadata != NULL, it means creating the
5126 * striped directory with specified stripeEA, then it
5127 * should ignore the default stripeEA */
5128 if (hint != NULL && hint->dah_eadata == NULL) {
5129 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STALE_DIR_LAYOUT))
5130 GOTO(out, rc = -EREMOTE);
5132 if (lo->ldo_dir_stripe_offset == -1) {
5133 /* child and parent should be in the same MDT */
5134 if (hint->dah_parent != NULL &&
5135 dt_object_remote(hint->dah_parent))
5136 GOTO(out, rc = -EREMOTE);
5137 } else if (lo->ldo_dir_stripe_offset !=
5139 struct lod_device *lod;
5140 struct lod_tgt_descs *ltd;
5141 struct lod_tgt_desc *tgt = NULL;
5142 bool found_mdt = false;
5145 lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
5146 ltd = &lod->lod_mdt_descs;
5147 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
5148 tgt = LTD_TGT(ltd, i);
5149 if (tgt->ltd_index ==
5150 lo->ldo_dir_stripe_offset) {
5156 /* If the MDT indicated by stripe_offset can be
5157 * found, then tell client to resend the create
5158 * request to the correct MDT, otherwise return
5159 * error to client */
5161 GOTO(out, rc = -EREMOTE);
5163 GOTO(out, rc = -EINVAL);
5165 } else if (hint && hint->dah_eadata) {
5167 lmu->lb_buf = (void *)hint->dah_eadata;
5168 lmu->lb_len = hint->dah_eadata_len;
5171 rc = lod_declare_dir_striping_create(env, dt, attr, lmu, dof,
5175 /* failed to create striping or to set initial size, let's reset
5176 * config so that others don't get confused */
5178 lod_striping_free(env, lo);
5183 * Generate component ID for new created component.
5185 * \param[in] lo LOD object
5186 * \param[in] comp_idx index of ldo_comp_entries
5188 * \retval component ID on success
5189 * \retval LCME_ID_INVAL on failure
5191 static __u32 lod_gen_component_id(struct lod_object *lo,
5192 int mirror_id, int comp_idx)
5194 struct lod_layout_component *lod_comp;
5195 __u32 id, start, end;
5198 LASSERT(lo->ldo_comp_entries[comp_idx].llc_id == LCME_ID_INVAL);
5200 lod_obj_inc_layout_gen(lo);
5201 id = lo->ldo_layout_gen;
5202 if (likely(id <= SEQ_ID_MAX))
5203 RETURN(pflr_id(mirror_id, id & SEQ_ID_MASK));
5205 /* Layout generation wraps, need to check collisions. */
5206 start = id & SEQ_ID_MASK;
5209 for (id = start; id <= end; id++) {
5210 for (i = 0; i < lo->ldo_comp_cnt; i++) {
5211 lod_comp = &lo->ldo_comp_entries[i];
5212 if (pflr_id(mirror_id, id) == lod_comp->llc_id)
5215 /* Found the ununsed ID */
5216 if (i == lo->ldo_comp_cnt)
5217 RETURN(pflr_id(mirror_id, id));
5219 if (end == LCME_ID_MAX) {
5221 end = min(lo->ldo_layout_gen & LCME_ID_MASK,
5222 (__u32)(LCME_ID_MAX - 1));
5226 RETURN(LCME_ID_INVAL);
5230 * Creation of a striped regular object.
5232 * The function is called to create the stripe objects for a regular
5233 * striped file. This can happen at the initial object creation or
5234 * when the caller asks LOD to do so using ->do_xattr_set() method
5235 * (so called late striping). Notice all the information are already
5236 * prepared in the form of the list of objects (ldo_stripe field).
5237 * This is done during declare phase.
5239 * \param[in] env execution environment
5240 * \param[in] dt object
5241 * \param[in] attr attributes the stripes will be created with
5242 * \param[in] dof format of stripes (see OSD API description)
5243 * \param[in] th transaction handle
5245 * \retval 0 on success
5246 * \retval negative if failed
5248 int lod_striped_create(const struct lu_env *env, struct dt_object *dt,
5249 struct lu_attr *attr, struct dt_object_format *dof,
5252 struct lod_layout_component *lod_comp;
5253 struct lod_object *lo = lod_dt_obj(dt);
5258 LASSERT(lo->ldo_comp_cnt != 0 && lo->ldo_comp_entries != NULL);
5260 mirror_id = 0; /* non-flr file's mirror_id is 0 */
5261 if (lo->ldo_mirror_count > 1) {
5262 for (i = 0; i < lo->ldo_comp_cnt; i++) {
5263 lod_comp = &lo->ldo_comp_entries[i];
5264 if (lod_comp->llc_id != LCME_ID_INVAL &&
5265 mirror_id_of(lod_comp->llc_id) > mirror_id)
5266 mirror_id = mirror_id_of(lod_comp->llc_id);
5270 /* create all underlying objects */
5271 for (i = 0; i < lo->ldo_comp_cnt; i++) {
5272 lod_comp = &lo->ldo_comp_entries[i];
5274 if (lod_comp->llc_id == LCME_ID_INVAL) {
5275 /* only the component of FLR layout with more than 1
5276 * mirror has mirror ID in its component ID.
5278 if (lod_comp->llc_extent.e_start == 0 &&
5279 lo->ldo_mirror_count > 1)
5282 lod_comp->llc_id = lod_gen_component_id(lo,
5284 if (lod_comp->llc_id == LCME_ID_INVAL)
5285 GOTO(out, rc = -ERANGE);
5288 if (lod_comp_inited(lod_comp))
5291 if (lod_comp->llc_pattern & LOV_PATTERN_F_RELEASED)
5292 lod_comp_set_init(lod_comp);
5294 if (lov_pattern(lod_comp->llc_pattern) == LOV_PATTERN_MDT)
5295 lod_comp_set_init(lod_comp);
5297 if (lod_comp->llc_stripe == NULL)
5300 LASSERT(lod_comp->llc_stripe_count);
5301 for (j = 0; j < lod_comp->llc_stripe_count; j++) {
5302 struct dt_object *object = lod_comp->llc_stripe[j];
5303 LASSERT(object != NULL);
5304 rc = lod_sub_create(env, object, attr, NULL, dof, th);
5308 lod_comp_set_init(lod_comp);
5311 rc = lod_fill_mirrors(lo);
5315 rc = lod_generate_and_set_lovea(env, lo, th);
5319 lo->ldo_comp_cached = 1;
5323 lod_striping_free(env, lo);
5327 static inline bool lod_obj_is_dom(struct dt_object *dt)
5329 struct lod_object *lo = lod_dt_obj(dt);
5331 if (!dt_object_exists(dt_object_child(dt)))
5334 if (S_ISDIR(dt->do_lu.lo_header->loh_attr))
5337 if (!lo->ldo_comp_cnt)
5340 return (lov_pattern(lo->ldo_comp_entries[0].llc_pattern) ==
5345 * Implementation of dt_object_operations::do_create.
5347 * If any of preceeding methods (like ->do_declare_create(),
5348 * ->do_ah_init(), etc) chose to create a striped object,
5349 * then this method will create the master and the stripes.
5351 * \see dt_object_operations::do_create() in the API description for details.
5353 static int lod_create(const struct lu_env *env, struct dt_object *dt,
5354 struct lu_attr *attr, struct dt_allocation_hint *hint,
5355 struct dt_object_format *dof, struct thandle *th)
5360 /* create local object */
5361 rc = lod_sub_create(env, dt_object_child(dt), attr, hint, dof, th);
5365 if (S_ISREG(dt->do_lu.lo_header->loh_attr) &&
5366 (lod_obj_is_striped(dt) || lod_obj_is_dom(dt)) &&
5367 dof->u.dof_reg.striped != 0) {
5368 LASSERT(lod_dt_obj(dt)->ldo_comp_cached == 0);
5369 rc = lod_striped_create(env, dt, attr, dof, th);
5376 lod_obj_stripe_destroy_cb(const struct lu_env *env, struct lod_object *lo,
5377 struct dt_object *dt, struct thandle *th,
5378 int comp_idx, int stripe_idx,
5379 struct lod_obj_stripe_cb_data *data)
5381 if (data->locd_declare)
5382 return lod_sub_declare_destroy(env, dt, th);
5383 else if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_SPEOBJ) ||
5384 stripe_idx == cfs_fail_val)
5385 return lod_sub_destroy(env, dt, th);
5391 * Implementation of dt_object_operations::do_declare_destroy.
5393 * If the object is a striped directory, then the function declares reference
5394 * removal from the master object (this is an index) to the stripes and declares
5395 * destroy of all the stripes. In all the cases, it declares an intention to
5396 * destroy the object itself.
5398 * \see dt_object_operations::do_declare_destroy() in the API description
5401 static int lod_declare_destroy(const struct lu_env *env, struct dt_object *dt,
5404 struct dt_object *next = dt_object_child(dt);
5405 struct lod_object *lo = lod_dt_obj(dt);
5406 struct lod_thread_info *info = lod_env_info(env);
5407 char *stripe_name = info->lti_key;
5412 * load striping information, notice we don't do this when object
5413 * is being initialized as we don't need this information till
5414 * few specific cases like destroy, chown
5416 rc = lod_striping_load(env, lo);
5420 /* declare destroy for all underlying objects */
5421 if (S_ISDIR(dt->do_lu.lo_header->loh_attr)) {
5422 rc = next->do_ops->do_index_try(env, next,
5423 &dt_directory_features);
5427 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
5428 rc = lod_sub_declare_ref_del(env, next, th);
5432 snprintf(stripe_name, sizeof(info->lti_key), DFID":%d",
5433 PFID(lu_object_fid(&lo->ldo_stripe[i]->do_lu)),
5435 rc = lod_sub_declare_delete(env, next,
5436 (const struct dt_key *)stripe_name, th);
5443 * we declare destroy for the local object
5445 rc = lod_sub_declare_destroy(env, next, th);
5449 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ) ||
5450 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ2))
5453 if (!lod_obj_is_striped(dt))
5456 /* declare destroy all striped objects */
5457 if (S_ISDIR(dt->do_lu.lo_header->loh_attr)) {
5458 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
5459 if (lo->ldo_stripe[i] == NULL)
5462 rc = lod_sub_declare_ref_del(env, lo->ldo_stripe[i],
5465 rc = lod_sub_declare_destroy(env, lo->ldo_stripe[i],
5471 struct lod_obj_stripe_cb_data data = { { 0 } };
5473 data.locd_declare = true;
5474 data.locd_stripe_cb = lod_obj_stripe_destroy_cb;
5475 rc = lod_obj_for_each_stripe(env, lo, th, &data);
5482 * Implementation of dt_object_operations::do_destroy.
5484 * If the object is a striped directory, then the function removes references
5485 * from the master object (this is an index) to the stripes and destroys all
5486 * the stripes. In all the cases, the function destroys the object itself.
5488 * \see dt_object_operations::do_destroy() in the API description for details.
5490 static int lod_destroy(const struct lu_env *env, struct dt_object *dt,
5493 struct dt_object *next = dt_object_child(dt);
5494 struct lod_object *lo = lod_dt_obj(dt);
5495 struct lod_thread_info *info = lod_env_info(env);
5496 char *stripe_name = info->lti_key;
5501 /* destroy sub-stripe of master object */
5502 if (S_ISDIR(dt->do_lu.lo_header->loh_attr)) {
5503 rc = next->do_ops->do_index_try(env, next,
5504 &dt_directory_features);
5508 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
5509 rc = lod_sub_ref_del(env, next, th);
5513 snprintf(stripe_name, sizeof(info->lti_key), DFID":%d",
5514 PFID(lu_object_fid(&lo->ldo_stripe[i]->do_lu)),
5517 CDEBUG(D_INFO, DFID" delete stripe %s "DFID"\n",
5518 PFID(lu_object_fid(&dt->do_lu)), stripe_name,
5519 PFID(lu_object_fid(&lo->ldo_stripe[i]->do_lu)));
5521 rc = lod_sub_delete(env, next,
5522 (const struct dt_key *)stripe_name, th);
5528 rc = lod_sub_destroy(env, next, th);
5532 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ) ||
5533 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ2))
5536 if (!lod_obj_is_striped(dt))
5539 /* destroy all striped objects */
5540 if (S_ISDIR(dt->do_lu.lo_header->loh_attr)) {
5541 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
5542 if (lo->ldo_stripe[i] == NULL)
5544 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_SPEOBJ) ||
5545 i == cfs_fail_val) {
5546 dt_write_lock(env, lo->ldo_stripe[i],
5548 rc = lod_sub_ref_del(env, lo->ldo_stripe[i],
5550 dt_write_unlock(env, lo->ldo_stripe[i]);
5554 rc = lod_sub_destroy(env, lo->ldo_stripe[i],
5561 struct lod_obj_stripe_cb_data data = { { 0 } };
5563 data.locd_declare = false;
5564 data.locd_stripe_cb = lod_obj_stripe_destroy_cb;
5565 rc = lod_obj_for_each_stripe(env, lo, th, &data);
5572 * Implementation of dt_object_operations::do_declare_ref_add.
5574 * \see dt_object_operations::do_declare_ref_add() in the API description
5577 static int lod_declare_ref_add(const struct lu_env *env,
5578 struct dt_object *dt, struct thandle *th)
5580 return lod_sub_declare_ref_add(env, dt_object_child(dt), th);
5584 * Implementation of dt_object_operations::do_ref_add.
5586 * \see dt_object_operations::do_ref_add() in the API description for details.
5588 static int lod_ref_add(const struct lu_env *env,
5589 struct dt_object *dt, struct thandle *th)
5591 return lod_sub_ref_add(env, dt_object_child(dt), th);
5595 * Implementation of dt_object_operations::do_declare_ref_del.
5597 * \see dt_object_operations::do_declare_ref_del() in the API description
5600 static int lod_declare_ref_del(const struct lu_env *env,
5601 struct dt_object *dt, struct thandle *th)
5603 return lod_sub_declare_ref_del(env, dt_object_child(dt), th);
5607 * Implementation of dt_object_operations::do_ref_del
5609 * \see dt_object_operations::do_ref_del() in the API description for details.
5611 static int lod_ref_del(const struct lu_env *env,
5612 struct dt_object *dt, struct thandle *th)
5614 return lod_sub_ref_del(env, dt_object_child(dt), th);
5618 * Implementation of dt_object_operations::do_object_sync.
5620 * \see dt_object_operations::do_object_sync() in the API description
5623 static int lod_object_sync(const struct lu_env *env, struct dt_object *dt,
5624 __u64 start, __u64 end)
5626 return dt_object_sync(env, dt_object_child(dt), start, end);
5630 * Implementation of dt_object_operations::do_object_unlock.
5632 * Used to release LDLM lock(s).
5634 * \see dt_object_operations::do_object_unlock() in the API description
5637 static int lod_object_unlock(const struct lu_env *env, struct dt_object *dt,
5638 struct ldlm_enqueue_info *einfo,
5639 union ldlm_policy_data *policy)
5641 struct lod_object *lo = lod_dt_obj(dt);
5642 struct lustre_handle_array *slave_locks = einfo->ei_cbdata;
5643 int slave_locks_size;
5647 if (slave_locks == NULL)
5650 LASSERT(S_ISDIR(dt->do_lu.lo_header->loh_attr));
5651 /* Note: for remote lock for single stripe dir, MDT will cancel
5652 * the lock by lockh directly */
5653 LASSERT(!dt_object_remote(dt_object_child(dt)));
5655 /* locks were unlocked in MDT layer */
5656 for (i = 0; i < slave_locks->ha_count; i++)
5657 LASSERT(!lustre_handle_is_used(&slave_locks->ha_handles[i]));
5660 * NB, ha_count may not equal to ldo_dir_stripe_count, because dir
5661 * layout may change, e.g., shrink dir layout after migration.
5663 for (i = 0; i < lo->ldo_dir_stripe_count; i++)
5664 dt_invalidate(env, lo->ldo_stripe[i]);
5666 slave_locks_size = offsetof(typeof(*slave_locks),
5667 ha_handles[slave_locks->ha_count]);
5668 OBD_FREE(slave_locks, slave_locks_size);
5669 einfo->ei_cbdata = NULL;
5675 * Implementation of dt_object_operations::do_object_lock.
5677 * Used to get LDLM lock on the non-striped and striped objects.
5679 * \see dt_object_operations::do_object_lock() in the API description
5682 static int lod_object_lock(const struct lu_env *env,
5683 struct dt_object *dt,
5684 struct lustre_handle *lh,
5685 struct ldlm_enqueue_info *einfo,
5686 union ldlm_policy_data *policy)
5688 struct lod_object *lo = lod_dt_obj(dt);
5689 int slave_locks_size;
5690 struct lustre_handle_array *slave_locks = NULL;
5695 /* remote object lock */
5696 if (!einfo->ei_enq_slave) {
5697 LASSERT(dt_object_remote(dt));
5698 return dt_object_lock(env, dt_object_child(dt), lh, einfo,
5702 if (!S_ISDIR(dt->do_lu.lo_header->loh_attr))
5705 rc = lod_striping_load(env, lo);
5710 if (lo->ldo_dir_stripe_count <= 1)
5713 slave_locks_size = offsetof(typeof(*slave_locks),
5714 ha_handles[lo->ldo_dir_stripe_count]);
5715 /* Freed in lod_object_unlock */
5716 OBD_ALLOC(slave_locks, slave_locks_size);
5719 slave_locks->ha_count = lo->ldo_dir_stripe_count;
5721 /* striped directory lock */
5722 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
5723 struct lustre_handle lockh;
5724 struct ldlm_res_id *res_id;
5726 res_id = &lod_env_info(env)->lti_res_id;
5727 fid_build_reg_res_name(lu_object_fid(&lo->ldo_stripe[i]->do_lu),
5729 einfo->ei_res_id = res_id;
5731 LASSERT(lo->ldo_stripe[i] != NULL);
5732 if (dt_object_remote(lo->ldo_stripe[i])) {
5733 set_bit(i, (void *)slave_locks->ha_map);
5734 rc = dt_object_lock(env, lo->ldo_stripe[i], &lockh,
5737 struct ldlm_namespace *ns = einfo->ei_namespace;
5738 ldlm_blocking_callback blocking = einfo->ei_cb_local_bl;
5739 ldlm_completion_callback completion = einfo->ei_cb_cp;
5740 __u64 dlmflags = LDLM_FL_ATOMIC_CB;
5742 if (einfo->ei_mode == LCK_PW ||
5743 einfo->ei_mode == LCK_EX)
5744 dlmflags |= LDLM_FL_COS_INCOMPAT;
5746 LASSERT(ns != NULL);
5747 rc = ldlm_cli_enqueue_local(env, ns, res_id, LDLM_IBITS,
5748 policy, einfo->ei_mode,
5749 &dlmflags, blocking,
5751 NULL, 0, LVB_T_NONE,
5756 ldlm_lock_decref_and_cancel(
5757 &slave_locks->ha_handles[i],
5759 OBD_FREE(slave_locks, slave_locks_size);
5762 slave_locks->ha_handles[i] = lockh;
5764 einfo->ei_cbdata = slave_locks;
5770 * Implementation of dt_object_operations::do_invalidate.
5772 * \see dt_object_operations::do_invalidate() in the API description for details
5774 static int lod_invalidate(const struct lu_env *env, struct dt_object *dt)
5776 return dt_invalidate(env, dt_object_child(dt));
5779 static int lod_layout_data_init(struct lod_thread_info *info, __u32 comp_cnt)
5783 /* clear memory region that will be used for layout change */
5784 memset(&info->lti_layout_attr, 0, sizeof(struct lu_attr));
5785 info->lti_count = 0;
5787 if (info->lti_comp_size >= comp_cnt)
5790 if (info->lti_comp_size > 0) {
5791 OBD_FREE(info->lti_comp_idx,
5792 info->lti_comp_size * sizeof(__u32));
5793 info->lti_comp_size = 0;
5796 OBD_ALLOC(info->lti_comp_idx, comp_cnt * sizeof(__u32));
5797 if (!info->lti_comp_idx)
5800 info->lti_comp_size = comp_cnt;
5804 static int lod_declare_instantiate_components(const struct lu_env *env,
5805 struct lod_object *lo, struct thandle *th)
5807 struct lod_thread_info *info = lod_env_info(env);
5812 LASSERT(info->lti_count < lo->ldo_comp_cnt);
5814 for (i = 0; i < info->lti_count; i++) {
5815 rc = lod_qos_prep_create(env, lo, NULL, th,
5816 info->lti_comp_idx[i]);
5822 info->lti_buf.lb_len = lod_comp_md_size(lo, false);
5823 rc = lod_sub_declare_xattr_set(env, lod_object_child(lo),
5824 &info->lti_buf, XATTR_NAME_LOV, 0, th);
5830 static int lod_declare_update_plain(const struct lu_env *env,
5831 struct lod_object *lo, struct layout_intent *layout,
5832 const struct lu_buf *buf, struct thandle *th)
5834 struct lod_thread_info *info = lod_env_info(env);
5835 struct lod_device *d = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
5836 struct lod_layout_component *lod_comp;
5837 struct lov_comp_md_v1 *comp_v1 = NULL;
5838 bool replay = false;
5842 LASSERT(lo->ldo_flr_state == LCM_FL_NONE);
5845 * In case the client is passing lovea, which only happens during
5846 * the replay of layout intent write RPC for now, we may need to
5847 * parse the lovea and apply new layout configuration.
5849 if (buf && buf->lb_len) {
5850 struct lov_user_md_v1 *v1 = buf->lb_buf;
5852 if (v1->lmm_magic != (LOV_MAGIC_DEFINED | LOV_MAGIC_COMP_V1) &&
5853 v1->lmm_magic != __swab32(LOV_MAGIC_DEFINED |
5854 LOV_MAGIC_COMP_V1)) {
5855 CERROR("%s: the replay buffer of layout extend "
5856 "(magic %#x) does not contain expected "
5857 "composite layout.\n",
5858 lod2obd(d)->obd_name, v1->lmm_magic);
5859 GOTO(out, rc = -EINVAL);
5862 rc = lod_use_defined_striping(env, lo, buf);
5865 lo->ldo_comp_cached = 1;
5867 rc = lod_get_lov_ea(env, lo);
5870 /* old on-disk EA is stored in info->lti_buf */
5871 comp_v1 = (struct lov_comp_md_v1 *)info->lti_buf.lb_buf;
5874 /* non replay path */
5875 rc = lod_striping_load(env, lo);
5880 /* Make sure defined layout covers the requested write range. */
5881 lod_comp = &lo->ldo_comp_entries[lo->ldo_comp_cnt - 1];
5882 if (lo->ldo_comp_cnt > 1 &&
5883 lod_comp->llc_extent.e_end != OBD_OBJECT_EOF &&
5884 lod_comp->llc_extent.e_end < layout->li_extent.e_end) {
5885 CDEBUG(replay ? D_ERROR : D_LAYOUT,
5886 "%s: the defined layout [0, %#llx) does not covers "
5887 "the write range "DEXT"\n",
5888 lod2obd(d)->obd_name, lod_comp->llc_extent.e_end,
5889 PEXT(&layout->li_extent));
5890 GOTO(out, rc = -EINVAL);
5893 CDEBUG(D_LAYOUT, "%s: "DFID": instantiate components "DEXT"\n",
5894 lod2obd(d)->obd_name, PFID(lod_object_fid(lo)),
5895 PEXT(&layout->li_extent));
5898 * Iterate ld->ldo_comp_entries, find the component whose extent under
5899 * the write range and not instantianted.
5901 for (i = 0; i < lo->ldo_comp_cnt; i++) {
5902 lod_comp = &lo->ldo_comp_entries[i];
5904 if (lod_comp->llc_extent.e_start >= layout->li_extent.e_end)
5908 if (lod_comp_inited(lod_comp))
5912 * In replay path, lod_comp is the EA passed by
5913 * client replay buffer, comp_v1 is the pre-recovery
5914 * on-disk EA, we'd sift out those components which
5915 * were init-ed in the on-disk EA.
5917 if (le32_to_cpu(comp_v1->lcm_entries[i].lcme_flags) &
5922 * this component hasn't instantiated in normal path, or during
5923 * replay it needs replay the instantiation.
5926 /* A released component is being extended */
5927 if (lod_comp->llc_pattern & LOV_PATTERN_F_RELEASED)
5928 GOTO(out, rc = -EINVAL);
5930 LASSERT(info->lti_comp_idx != NULL);
5931 info->lti_comp_idx[info->lti_count++] = i;
5934 if (info->lti_count == 0)
5937 lod_obj_inc_layout_gen(lo);
5938 rc = lod_declare_instantiate_components(env, lo, th);
5941 lod_striping_free(env, lo);
5945 static inline int lod_comp_index(struct lod_object *lo,
5946 struct lod_layout_component *lod_comp)
5948 LASSERT(lod_comp >= lo->ldo_comp_entries &&
5949 lod_comp <= &lo->ldo_comp_entries[lo->ldo_comp_cnt - 1]);
5951 return lod_comp - lo->ldo_comp_entries;
5955 * Stale other mirrors by writing extent.
5957 static void lod_stale_components(struct lod_object *lo, int primary,
5958 struct lu_extent *extent)
5960 struct lod_layout_component *pri_comp, *lod_comp;
5963 /* The writing extent decides which components in the primary
5964 * are affected... */
5965 CDEBUG(D_LAYOUT, "primary mirror %d, "DEXT"\n", primary, PEXT(extent));
5966 lod_foreach_mirror_comp(pri_comp, lo, primary) {
5967 if (!lu_extent_is_overlapped(extent, &pri_comp->llc_extent))
5970 CDEBUG(D_LAYOUT, "primary comp %u "DEXT"\n",
5971 lod_comp_index(lo, pri_comp),
5972 PEXT(&pri_comp->llc_extent));
5974 for (i = 0; i < lo->ldo_mirror_count; i++) {
5978 /* ... and then stale other components that are
5979 * overlapping with primary components */
5980 lod_foreach_mirror_comp(lod_comp, lo, i) {
5981 if (!lu_extent_is_overlapped(
5982 &pri_comp->llc_extent,
5983 &lod_comp->llc_extent))
5986 CDEBUG(D_LAYOUT, "stale: %u / %u\n",
5987 i, lod_comp_index(lo, lod_comp));
5989 lod_comp->llc_flags |= LCME_FL_STALE;
5990 lo->ldo_mirrors[i].lme_stale = 1;
5997 * check an OST's availability
5998 * \param[in] env execution environment
5999 * \param[in] lo lod object
6000 * \param[in] dt dt object
6001 * \param[in] index mirror index
6003 * \retval negative if failed
6004 * \retval 1 if \a dt is available
6005 * \retval 0 if \a dt is not available
6007 static inline int lod_check_ost_avail(const struct lu_env *env,
6008 struct lod_object *lo,
6009 struct dt_object *dt, int index)
6011 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
6012 struct lod_tgt_desc *ost;
6014 int type = LU_SEQ_RANGE_OST;
6017 rc = lod_fld_lookup(env, lod, lu_object_fid(&dt->do_lu), &idx, &type);
6019 CERROR("%s: can't locate "DFID":rc = %d\n",
6020 lod2obd(lod)->obd_name, PFID(lu_object_fid(&dt->do_lu)),
6025 ost = OST_TGT(lod, idx);
6026 if (ost->ltd_statfs.os_state &
6027 (OS_STATE_READONLY | OS_STATE_ENOSPC | OS_STATE_ENOINO |
6028 OS_STATE_NOPRECREATE) ||
6029 ost->ltd_active == 0) {
6030 CDEBUG(D_LAYOUT, DFID ": mirror %d OST%d unavail, rc = %d\n",
6031 PFID(lod_object_fid(lo)), index, idx, rc);
6039 * Pick primary mirror for write
6040 * \param[in] env execution environment
6041 * \param[in] lo object
6042 * \param[in] extent write range
6044 static int lod_primary_pick(const struct lu_env *env, struct lod_object *lo,
6045 struct lu_extent *extent)
6047 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
6048 unsigned int seq = 0;
6049 struct lod_layout_component *lod_comp;
6051 int picked = -1, second_pick = -1, third_pick = -1;
6054 if (OBD_FAIL_CHECK(OBD_FAIL_FLR_RANDOM_PICK_MIRROR)) {
6055 get_random_bytes(&seq, sizeof(seq));
6056 seq %= lo->ldo_mirror_count;
6060 * Pick a mirror as the primary, and check the availability of OSTs.
6062 * This algo can be revised later after knowing the topology of
6065 lod_qos_statfs_update(env, lod);
6066 for (i = 0; i < lo->ldo_mirror_count; i++) {
6067 bool ost_avail = true;
6068 int index = (i + seq) % lo->ldo_mirror_count;
6070 if (lo->ldo_mirrors[index].lme_stale) {
6071 CDEBUG(D_LAYOUT, DFID": mirror %d stale\n",
6072 PFID(lod_object_fid(lo)), index);
6076 /* 2nd pick is for the primary mirror containing unavail OST */
6077 if (lo->ldo_mirrors[index].lme_primary && second_pick < 0)
6078 second_pick = index;
6080 /* 3rd pick is for non-primary mirror containing unavail OST */
6081 if (second_pick < 0 && third_pick < 0)
6085 * we found a non-primary 1st pick, we'd like to find a
6086 * potential pirmary mirror.
6088 if (picked >= 0 && !lo->ldo_mirrors[index].lme_primary)
6091 /* check the availability of OSTs */
6092 lod_foreach_mirror_comp(lod_comp, lo, index) {
6093 if (!lod_comp_inited(lod_comp) || !lod_comp->llc_stripe)
6096 for (j = 0; j < lod_comp->llc_stripe_count; j++) {
6097 struct dt_object *dt = lod_comp->llc_stripe[j];
6099 rc = lod_check_ost_avail(env, lo, dt, index);
6106 } /* for all dt object in one component */
6109 } /* for all components in a mirror */
6112 * the OSTs where allocated objects locates in the components
6113 * of the mirror are available.
6118 /* this mirror has all OSTs available */
6122 * primary with all OSTs are available, this is the perfect
6125 if (lo->ldo_mirrors[index].lme_primary)
6127 } /* for all mirrors */
6129 /* failed to pick a sound mirror, lower our expectation */
6131 picked = second_pick;
6133 picked = third_pick;
6140 static int lod_prepare_resync_mirror(const struct lu_env *env,
6141 struct lod_object *lo,
6144 struct lod_thread_info *info = lod_env_info(env);
6145 struct lod_layout_component *lod_comp;
6148 for (i = 0; i < lo->ldo_mirror_count; i++) {
6149 if (lo->ldo_mirrors[i].lme_id != mirror_id)
6152 lod_foreach_mirror_comp(lod_comp, lo, i) {
6153 if (lod_comp_inited(lod_comp))
6156 info->lti_comp_idx[info->lti_count++] =
6157 lod_comp_index(lo, lod_comp);
6165 * figure out the components should be instantiated for resync.
6167 static int lod_prepare_resync(const struct lu_env *env, struct lod_object *lo,
6168 struct lu_extent *extent)
6170 struct lod_thread_info *info = lod_env_info(env);
6171 struct lod_layout_component *lod_comp;
6172 unsigned int need_sync = 0;
6176 DFID": instantiate all stale components in "DEXT"\n",
6177 PFID(lod_object_fid(lo)), PEXT(extent));
6180 * instantiate all components within this extent, even non-stale
6183 for (i = 0; i < lo->ldo_mirror_count; i++) {
6184 if (!lo->ldo_mirrors[i].lme_stale)
6187 lod_foreach_mirror_comp(lod_comp, lo, i) {
6188 if (!lu_extent_is_overlapped(extent,
6189 &lod_comp->llc_extent))
6194 if (lod_comp_inited(lod_comp))
6197 CDEBUG(D_LAYOUT, "resync instantiate %d / %d\n",
6198 i, lod_comp_index(lo, lod_comp));
6199 info->lti_comp_idx[info->lti_count++] =
6200 lod_comp_index(lo, lod_comp);
6204 return need_sync ? 0 : -EALREADY;
6207 static int lod_declare_update_rdonly(const struct lu_env *env,
6208 struct lod_object *lo, struct md_layout_change *mlc,
6211 struct lod_thread_info *info = lod_env_info(env);
6212 struct lu_attr *layout_attr = &info->lti_layout_attr;
6213 struct lod_layout_component *lod_comp;
6214 struct lu_extent extent = { 0 };
6218 LASSERT(lo->ldo_flr_state == LCM_FL_RDONLY);
6219 LASSERT(mlc->mlc_opc == MD_LAYOUT_WRITE ||
6220 mlc->mlc_opc == MD_LAYOUT_RESYNC);
6221 LASSERT(lo->ldo_mirror_count > 0);
6223 if (mlc->mlc_opc == MD_LAYOUT_WRITE) {
6224 struct layout_intent *layout = mlc->mlc_intent;
6227 extent = layout->li_extent;
6228 CDEBUG(D_LAYOUT, DFID": trying to write :"DEXT"\n",
6229 PFID(lod_object_fid(lo)), PEXT(&extent));
6231 picked = lod_primary_pick(env, lo, &extent);
6235 CDEBUG(D_LAYOUT, DFID": picked mirror id %u as primary\n",
6236 PFID(lod_object_fid(lo)),
6237 lo->ldo_mirrors[picked].lme_id);
6239 if (layout->li_opc == LAYOUT_INTENT_TRUNC) {
6241 * trunc transfers [0, size) in the intent extent, we'd
6242 * stale components overlapping [size, eof).
6244 extent.e_start = extent.e_end;
6245 extent.e_end = OBD_OBJECT_EOF;
6248 /* stale overlapping components from other mirrors */
6249 lod_stale_components(lo, picked, &extent);
6251 /* restore truncate intent extent */
6252 if (layout->li_opc == LAYOUT_INTENT_TRUNC)
6253 extent.e_end = extent.e_start;
6255 /* instantiate components for the picked mirror, start from 0 */
6258 lod_foreach_mirror_comp(lod_comp, lo, picked) {
6259 if (!lu_extent_is_overlapped(&extent,
6260 &lod_comp->llc_extent))
6263 if (lod_comp_inited(lod_comp))
6266 info->lti_comp_idx[info->lti_count++] =
6267 lod_comp_index(lo, lod_comp);
6270 lo->ldo_flr_state = LCM_FL_WRITE_PENDING;
6271 } else { /* MD_LAYOUT_RESYNC */
6275 * could contain multiple non-stale mirrors, so we need to
6276 * prep uninited all components assuming any non-stale mirror
6277 * could be picked as the primary mirror.
6279 if (mlc->mlc_mirror_id == 0) {
6281 for (i = 0; i < lo->ldo_mirror_count; i++) {
6282 if (lo->ldo_mirrors[i].lme_stale)
6285 lod_foreach_mirror_comp(lod_comp, lo, i) {
6286 if (!lod_comp_inited(lod_comp))
6290 lod_comp->llc_extent.e_end)
6292 lod_comp->llc_extent.e_end;
6295 rc = lod_prepare_resync(env, lo, &extent);
6299 /* mirror write, try to init its all components */
6300 rc = lod_prepare_resync_mirror(env, lo,
6301 mlc->mlc_mirror_id);
6306 /* change the file state to SYNC_PENDING */
6307 lo->ldo_flr_state = LCM_FL_SYNC_PENDING;
6310 /* Reset the layout version once it's becoming too large.
6311 * This way it can make sure that the layout version is
6312 * monotonously increased in this writing era. */
6313 lod_obj_inc_layout_gen(lo);
6314 if (lo->ldo_layout_gen > (LCME_ID_MAX >> 1)) {
6315 __u32 layout_version;
6317 cfs_get_random_bytes(&layout_version, sizeof(layout_version));
6318 lo->ldo_layout_gen = layout_version & 0xffff;
6321 rc = lod_declare_instantiate_components(env, lo, th);
6325 layout_attr->la_valid = LA_LAYOUT_VERSION;
6326 layout_attr->la_layout_version = 0; /* set current version */
6327 if (mlc->mlc_opc == MD_LAYOUT_RESYNC)
6328 layout_attr->la_layout_version = LU_LAYOUT_RESYNC;
6329 rc = lod_declare_attr_set(env, &lo->ldo_obj, layout_attr, th);
6335 lod_striping_free(env, lo);
6339 static int lod_declare_update_write_pending(const struct lu_env *env,
6340 struct lod_object *lo, struct md_layout_change *mlc,
6343 struct lod_thread_info *info = lod_env_info(env);
6344 struct lu_attr *layout_attr = &info->lti_layout_attr;
6345 struct lod_layout_component *lod_comp;
6346 struct lu_extent extent = { 0 };
6352 LASSERT(lo->ldo_flr_state == LCM_FL_WRITE_PENDING);
6353 LASSERT(mlc->mlc_opc == MD_LAYOUT_WRITE ||
6354 mlc->mlc_opc == MD_LAYOUT_RESYNC);
6356 /* look for the primary mirror */
6357 for (i = 0; i < lo->ldo_mirror_count; i++) {
6358 if (lo->ldo_mirrors[i].lme_stale)
6361 LASSERTF(primary < 0, DFID " has multiple primary: %u / %u",
6362 PFID(lod_object_fid(lo)),
6363 lo->ldo_mirrors[i].lme_id,
6364 lo->ldo_mirrors[primary].lme_id);
6369 CERROR(DFID ": doesn't have a primary mirror\n",
6370 PFID(lod_object_fid(lo)));
6371 GOTO(out, rc = -ENODATA);
6374 CDEBUG(D_LAYOUT, DFID": found primary %u\n",
6375 PFID(lod_object_fid(lo)), lo->ldo_mirrors[primary].lme_id);
6377 LASSERT(!lo->ldo_mirrors[primary].lme_stale);
6379 /* for LAYOUT_WRITE opc, it has to do the following operations:
6380 * 1. stale overlapping componets from stale mirrors;
6381 * 2. instantiate components of the primary mirror;
6382 * 3. transfter layout version to all objects of the primary;
6384 * for LAYOUT_RESYNC opc, it will do:
6385 * 1. instantiate components of all stale mirrors;
6386 * 2. transfer layout version to all objects to close write era. */
6388 if (mlc->mlc_opc == MD_LAYOUT_WRITE) {
6389 LASSERT(mlc->mlc_intent != NULL);
6391 extent = mlc->mlc_intent->li_extent;
6393 CDEBUG(D_LAYOUT, DFID": intent to write: "DEXT"\n",
6394 PFID(lod_object_fid(lo)), PEXT(&extent));
6396 if (mlc->mlc_intent->li_opc == LAYOUT_INTENT_TRUNC) {
6398 * trunc transfers [0, size) in the intent extent, we'd
6399 * stale components overlapping [size, eof).
6401 extent.e_start = extent.e_end;
6402 extent.e_end = OBD_OBJECT_EOF;
6404 /* 1. stale overlapping components */
6405 lod_stale_components(lo, primary, &extent);
6407 /* 2. find out the components need instantiating.
6408 * instantiate [0, mlc->mlc_intent->e_end) */
6410 /* restore truncate intent extent */
6411 if (mlc->mlc_intent->li_opc == LAYOUT_INTENT_TRUNC)
6412 extent.e_end = extent.e_start;
6415 lod_foreach_mirror_comp(lod_comp, lo, primary) {
6416 if (!lu_extent_is_overlapped(&extent,
6417 &lod_comp->llc_extent))
6420 if (lod_comp_inited(lod_comp))
6423 CDEBUG(D_LAYOUT, "write instantiate %d / %d\n",
6424 primary, lod_comp_index(lo, lod_comp));
6425 info->lti_comp_idx[info->lti_count++] =
6426 lod_comp_index(lo, lod_comp);
6428 } else { /* MD_LAYOUT_RESYNC */
6429 if (mlc->mlc_mirror_id == 0) {
6431 lod_foreach_mirror_comp(lod_comp, lo, primary) {
6432 if (!lod_comp_inited(lod_comp))
6435 extent.e_end = lod_comp->llc_extent.e_end;
6438 rc = lod_prepare_resync(env, lo, &extent);
6442 /* mirror write, try to init its all components */
6443 rc = lod_prepare_resync_mirror(env, lo,
6444 mlc->mlc_mirror_id);
6449 /* change the file state to SYNC_PENDING */
6450 lo->ldo_flr_state = LCM_FL_SYNC_PENDING;
6453 rc = lod_declare_instantiate_components(env, lo, th);
6457 /* 3. transfer layout version to OST objects.
6458 * transfer new layout version to OST objects so that stale writes
6459 * can be denied. It also ends an era of writing by setting
6460 * LU_LAYOUT_RESYNC. Normal client can never use this bit to
6461 * send write RPC; only resync RPCs could do it. */
6462 layout_attr->la_valid = LA_LAYOUT_VERSION;
6463 layout_attr->la_layout_version = 0; /* set current version */
6464 if (mlc->mlc_opc == MD_LAYOUT_RESYNC)
6465 layout_attr->la_layout_version = LU_LAYOUT_RESYNC;
6466 rc = lod_declare_attr_set(env, &lo->ldo_obj, layout_attr, th);
6470 lod_obj_inc_layout_gen(lo);
6473 lod_striping_free(env, lo);
6477 static int lod_declare_update_sync_pending(const struct lu_env *env,
6478 struct lod_object *lo, struct md_layout_change *mlc,
6481 struct lod_thread_info *info = lod_env_info(env);
6482 unsigned sync_components = 0;
6483 unsigned resync_components = 0;
6488 LASSERT(lo->ldo_flr_state == LCM_FL_SYNC_PENDING);
6489 LASSERT(mlc->mlc_opc == MD_LAYOUT_RESYNC_DONE ||
6490 mlc->mlc_opc == MD_LAYOUT_WRITE);
6492 CDEBUG(D_LAYOUT, DFID ": received op %d in sync pending\n",
6493 PFID(lod_object_fid(lo)), mlc->mlc_opc);
6495 if (mlc->mlc_opc == MD_LAYOUT_WRITE) {
6496 CDEBUG(D_LAYOUT, DFID": cocurrent write to sync pending\n",
6497 PFID(lod_object_fid(lo)));
6499 lo->ldo_flr_state = LCM_FL_WRITE_PENDING;
6500 return lod_declare_update_write_pending(env, lo, mlc, th);
6503 /* MD_LAYOUT_RESYNC_DONE */
6505 for (i = 0; i < lo->ldo_comp_cnt; i++) {
6506 struct lod_layout_component *lod_comp;
6509 lod_comp = &lo->ldo_comp_entries[i];
6511 if (!(lod_comp->llc_flags & LCME_FL_STALE)) {
6516 for (j = 0; j < mlc->mlc_resync_count; j++) {
6517 if (lod_comp->llc_id != mlc->mlc_resync_ids[j])
6520 mlc->mlc_resync_ids[j] = LCME_ID_INVAL;
6521 lod_comp->llc_flags &= ~LCME_FL_STALE;
6522 resync_components++;
6528 for (i = 0; i < mlc->mlc_resync_count; i++) {
6529 if (mlc->mlc_resync_ids[i] == LCME_ID_INVAL)
6532 CDEBUG(D_LAYOUT, DFID": lcme id %u (%d / %zd) not exist "
6533 "or already synced\n", PFID(lod_object_fid(lo)),
6534 mlc->mlc_resync_ids[i], i, mlc->mlc_resync_count);
6535 GOTO(out, rc = -EINVAL);
6538 if (!sync_components || (mlc->mlc_resync_count && !resync_components)) {
6539 CDEBUG(D_LAYOUT, DFID": no mirror in sync\n",
6540 PFID(lod_object_fid(lo)));
6542 /* tend to return an error code here to prevent
6543 * the MDT from setting SoM attribute */
6544 GOTO(out, rc = -EINVAL);
6547 CDEBUG(D_LAYOUT, DFID": resynced %u/%zu components\n",
6548 PFID(lod_object_fid(lo)),
6549 resync_components, mlc->mlc_resync_count);
6551 lo->ldo_flr_state = LCM_FL_RDONLY;
6552 lod_obj_inc_layout_gen(lo);
6554 info->lti_buf.lb_len = lod_comp_md_size(lo, false);
6555 rc = lod_sub_declare_xattr_set(env, lod_object_child(lo),
6556 &info->lti_buf, XATTR_NAME_LOV, 0, th);
6561 lod_striping_free(env, lo);
6565 static int lod_declare_layout_change(const struct lu_env *env,
6566 struct dt_object *dt, struct md_layout_change *mlc,
6569 struct lod_thread_info *info = lod_env_info(env);
6570 struct lod_object *lo = lod_dt_obj(dt);
6574 if (!S_ISREG(dt->do_lu.lo_header->loh_attr) || !dt_object_exists(dt) ||
6575 dt_object_remote(dt_object_child(dt)))
6578 rc = lod_striping_load(env, lo);
6582 LASSERT(lo->ldo_comp_cnt > 0);
6584 rc = lod_layout_data_init(info, lo->ldo_comp_cnt);
6588 switch (lo->ldo_flr_state) {
6590 rc = lod_declare_update_plain(env, lo, mlc->mlc_intent,
6594 rc = lod_declare_update_rdonly(env, lo, mlc, th);
6596 case LCM_FL_WRITE_PENDING:
6597 rc = lod_declare_update_write_pending(env, lo, mlc, th);
6599 case LCM_FL_SYNC_PENDING:
6600 rc = lod_declare_update_sync_pending(env, lo, mlc, th);
6611 * Instantiate layout component objects which covers the intent write offset.
6613 static int lod_layout_change(const struct lu_env *env, struct dt_object *dt,
6614 struct md_layout_change *mlc, struct thandle *th)
6616 struct lu_attr *attr = &lod_env_info(env)->lti_attr;
6617 struct lu_attr *layout_attr = &lod_env_info(env)->lti_layout_attr;
6618 struct lod_object *lo = lod_dt_obj(dt);
6621 rc = lod_striped_create(env, dt, attr, NULL, th);
6622 if (!rc && layout_attr->la_valid & LA_LAYOUT_VERSION) {
6623 layout_attr->la_layout_version |= lo->ldo_layout_gen;
6624 rc = lod_attr_set(env, dt, layout_attr, th);
6630 struct dt_object_operations lod_obj_ops = {
6631 .do_read_lock = lod_read_lock,
6632 .do_write_lock = lod_write_lock,
6633 .do_read_unlock = lod_read_unlock,
6634 .do_write_unlock = lod_write_unlock,
6635 .do_write_locked = lod_write_locked,
6636 .do_attr_get = lod_attr_get,
6637 .do_declare_attr_set = lod_declare_attr_set,
6638 .do_attr_set = lod_attr_set,
6639 .do_xattr_get = lod_xattr_get,
6640 .do_declare_xattr_set = lod_declare_xattr_set,
6641 .do_xattr_set = lod_xattr_set,
6642 .do_declare_xattr_del = lod_declare_xattr_del,
6643 .do_xattr_del = lod_xattr_del,
6644 .do_xattr_list = lod_xattr_list,
6645 .do_ah_init = lod_ah_init,
6646 .do_declare_create = lod_declare_create,
6647 .do_create = lod_create,
6648 .do_declare_destroy = lod_declare_destroy,
6649 .do_destroy = lod_destroy,
6650 .do_index_try = lod_index_try,
6651 .do_declare_ref_add = lod_declare_ref_add,
6652 .do_ref_add = lod_ref_add,
6653 .do_declare_ref_del = lod_declare_ref_del,
6654 .do_ref_del = lod_ref_del,
6655 .do_object_sync = lod_object_sync,
6656 .do_object_lock = lod_object_lock,
6657 .do_object_unlock = lod_object_unlock,
6658 .do_invalidate = lod_invalidate,
6659 .do_declare_layout_change = lod_declare_layout_change,
6660 .do_layout_change = lod_layout_change,
6664 * Implementation of dt_body_operations::dbo_read.
6666 * \see dt_body_operations::dbo_read() in the API description for details.
6668 static ssize_t lod_read(const struct lu_env *env, struct dt_object *dt,
6669 struct lu_buf *buf, loff_t *pos)
6671 struct dt_object *next = dt_object_child(dt);
6673 LASSERT(S_ISREG(dt->do_lu.lo_header->loh_attr) ||
6674 S_ISLNK(dt->do_lu.lo_header->loh_attr));
6675 return next->do_body_ops->dbo_read(env, next, buf, pos);
6679 * Implementation of dt_body_operations::dbo_declare_write.
6681 * \see dt_body_operations::dbo_declare_write() in the API description
6684 static ssize_t lod_declare_write(const struct lu_env *env,
6685 struct dt_object *dt,
6686 const struct lu_buf *buf, loff_t pos,
6689 return lod_sub_declare_write(env, dt_object_child(dt), buf, pos, th);
6693 * Implementation of dt_body_operations::dbo_write.
6695 * \see dt_body_operations::dbo_write() in the API description for details.
6697 static ssize_t lod_write(const struct lu_env *env, struct dt_object *dt,
6698 const struct lu_buf *buf, loff_t *pos,
6701 LASSERT(S_ISREG(dt->do_lu.lo_header->loh_attr) ||
6702 S_ISLNK(dt->do_lu.lo_header->loh_attr));
6703 return lod_sub_write(env, dt_object_child(dt), buf, pos, th);
6706 static int lod_declare_punch(const struct lu_env *env, struct dt_object *dt,
6707 __u64 start, __u64 end, struct thandle *th)
6709 if (dt_object_remote(dt))
6712 return lod_sub_declare_punch(env, dt_object_child(dt), start, end, th);
6715 static int lod_punch(const struct lu_env *env, struct dt_object *dt,
6716 __u64 start, __u64 end, struct thandle *th)
6718 if (dt_object_remote(dt))
6721 LASSERT(S_ISREG(dt->do_lu.lo_header->loh_attr));
6722 return lod_sub_punch(env, dt_object_child(dt), start, end, th);
6726 * different type of files use the same body_ops because object may be created
6727 * in OUT, where there is no chance to set correct body_ops for each type, so
6728 * body_ops themselves will check file type inside, see lod_read/write/punch for
6731 const struct dt_body_operations lod_body_ops = {
6732 .dbo_read = lod_read,
6733 .dbo_declare_write = lod_declare_write,
6734 .dbo_write = lod_write,
6735 .dbo_declare_punch = lod_declare_punch,
6736 .dbo_punch = lod_punch,
6740 * Implementation of lu_object_operations::loo_object_init.
6742 * The function determines the type and the index of the target device using
6743 * sequence of the object's FID. Then passes control down to the
6744 * corresponding device:
6745 * OSD for the local objects, OSP for remote
6747 * \see lu_object_operations::loo_object_init() in the API description
6750 static int lod_object_init(const struct lu_env *env, struct lu_object *lo,
6751 const struct lu_object_conf *conf)
6753 struct lod_device *lod = lu2lod_dev(lo->lo_dev);
6754 struct lu_device *cdev = NULL;
6755 struct lu_object *cobj;
6756 struct lod_tgt_descs *ltd = NULL;
6757 struct lod_tgt_desc *tgt;
6759 int type = LU_SEQ_RANGE_ANY;
6763 rc = lod_fld_lookup(env, lod, lu_object_fid(lo), &idx, &type);
6765 /* Note: Sometimes, it will Return EAGAIN here, see
6766 * ptrlpc_import_delay_req(), which might confuse
6767 * lu_object_find_at() and make it wait there incorrectly.
6768 * so we convert it to EIO here.*/
6775 if (type == LU_SEQ_RANGE_MDT &&
6776 idx == lu_site2seq(lo->lo_dev->ld_site)->ss_node_id) {
6777 cdev = &lod->lod_child->dd_lu_dev;
6778 } else if (type == LU_SEQ_RANGE_MDT) {
6779 ltd = &lod->lod_mdt_descs;
6781 } else if (type == LU_SEQ_RANGE_OST) {
6782 ltd = &lod->lod_ost_descs;
6789 if (ltd->ltd_tgts_size > idx &&
6790 cfs_bitmap_check(ltd->ltd_tgt_bitmap, idx)) {
6791 tgt = LTD_TGT(ltd, idx);
6793 LASSERT(tgt != NULL);
6794 LASSERT(tgt->ltd_tgt != NULL);
6796 cdev = &(tgt->ltd_tgt->dd_lu_dev);
6798 lod_putref(lod, ltd);
6801 if (unlikely(cdev == NULL))
6804 cobj = cdev->ld_ops->ldo_object_alloc(env, lo->lo_header, cdev);
6805 if (unlikely(cobj == NULL))
6808 lu2lod_obj(lo)->ldo_obj.do_body_ops = &lod_body_ops;
6810 lu_object_add(lo, cobj);
6817 * Release resources associated with striping.
6819 * If the object is striped (regular or directory), then release
6820 * the stripe objects references and free the ldo_stripe array.
6822 * \param[in] env execution environment
6823 * \param[in] lo object
6825 void lod_striping_free_nolock(const struct lu_env *env, struct lod_object *lo)
6827 struct lod_layout_component *lod_comp;
6830 if (lo->ldo_stripe != NULL) {
6831 LASSERT(lo->ldo_comp_entries == NULL);
6832 LASSERT(lo->ldo_dir_stripes_allocated > 0);
6834 for (i = 0; i < lo->ldo_dir_stripe_count; i++) {
6835 if (lo->ldo_stripe[i])
6836 dt_object_put(env, lo->ldo_stripe[i]);
6839 j = sizeof(struct dt_object *) * lo->ldo_dir_stripes_allocated;
6840 OBD_FREE(lo->ldo_stripe, j);
6841 lo->ldo_stripe = NULL;
6842 lo->ldo_dir_stripes_allocated = 0;
6843 lo->ldo_dir_stripe_loaded = 0;
6844 lo->ldo_dir_stripe_count = 0;
6845 } else if (lo->ldo_comp_entries != NULL) {
6846 for (i = 0; i < lo->ldo_comp_cnt; i++) {
6847 /* free lod_layout_component::llc_stripe array */
6848 lod_comp = &lo->ldo_comp_entries[i];
6850 if (lod_comp->llc_stripe == NULL)
6852 LASSERT(lod_comp->llc_stripes_allocated != 0);
6853 for (j = 0; j < lod_comp->llc_stripes_allocated; j++) {
6854 if (lod_comp->llc_stripe[j] != NULL)
6856 &lod_comp->llc_stripe[j]->do_lu);
6858 OBD_FREE(lod_comp->llc_stripe,
6859 sizeof(struct dt_object *) *
6860 lod_comp->llc_stripes_allocated);
6861 lod_comp->llc_stripe = NULL;
6862 OBD_FREE(lod_comp->llc_ost_indices,
6864 lod_comp->llc_stripes_allocated);
6865 lod_comp->llc_ost_indices = NULL;
6866 lod_comp->llc_stripes_allocated = 0;
6868 lod_free_comp_entries(lo);
6869 lo->ldo_comp_cached = 0;
6873 void lod_striping_free(const struct lu_env *env, struct lod_object *lo)
6875 mutex_lock(&lo->ldo_layout_mutex);
6876 lod_striping_free_nolock(env, lo);
6877 mutex_unlock(&lo->ldo_layout_mutex);
6881 * Implementation of lu_object_operations::loo_object_free.
6883 * \see lu_object_operations::loo_object_free() in the API description
6886 static void lod_object_free(const struct lu_env *env, struct lu_object *o)
6888 struct lod_object *lo = lu2lod_obj(o);
6890 /* release all underlying object pinned */
6891 lod_striping_free(env, lo);
6893 OBD_SLAB_FREE_PTR(lo, lod_object_kmem);
6897 * Implementation of lu_object_operations::loo_object_release.
6899 * \see lu_object_operations::loo_object_release() in the API description
6902 static void lod_object_release(const struct lu_env *env, struct lu_object *o)
6904 /* XXX: shouldn't we release everything here in case if object
6905 * creation failed before? */
6909 * Implementation of lu_object_operations::loo_object_print.
6911 * \see lu_object_operations::loo_object_print() in the API description
6914 static int lod_object_print(const struct lu_env *env, void *cookie,
6915 lu_printer_t p, const struct lu_object *l)
6917 struct lod_object *o = lu2lod_obj((struct lu_object *) l);
6919 return (*p)(env, cookie, LUSTRE_LOD_NAME"-object@%p", o);
6922 struct lu_object_operations lod_lu_obj_ops = {
6923 .loo_object_init = lod_object_init,
6924 .loo_object_free = lod_object_free,
6925 .loo_object_release = lod_object_release,
6926 .loo_object_print = lod_object_print,