Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1 | /* |
| 2 | * GPL HEADER START |
| 3 | * |
| 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 only, |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License version 2 for more details (a copy is included |
| 14 | * in the LICENSE file that accompanied this code). |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * version 2 along with this program; If not, see |
Oleg Drokin | 6a5b99a | 2016-06-14 23:33:40 -0400 | [diff] [blame] | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 19 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 20 | * GPL HEADER END |
| 21 | */ |
| 22 | /* |
| 23 | * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
| 24 | * Use is subject to license terms. |
| 25 | * |
Andreas Dilger | 1dc563a | 2015-11-08 18:09:37 -0500 | [diff] [blame] | 26 | * Copyright (c) 2011, 2015, Intel Corporation. |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 27 | */ |
| 28 | /* |
| 29 | * This file is part of Lustre, http://www.lustre.org/ |
| 30 | * Lustre is a trademark of Sun Microsystems, Inc. |
| 31 | * |
| 32 | * lustre/lov/lov_ea.c |
| 33 | * |
| 34 | * Author: Wang Di <wangdi@clusterfs.com> |
| 35 | */ |
| 36 | |
| 37 | #define DEBUG_SUBSYSTEM S_LOV |
| 38 | |
| 39 | #include <asm/div64.h> |
Greg Kroah-Hartman | 9fdaf8c | 2014-07-11 20:51:16 -0700 | [diff] [blame] | 40 | #include "../../include/linux/libcfs/libcfs.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 41 | |
Greg Kroah-Hartman | 0cf0f7a | 2014-07-11 22:01:58 -0700 | [diff] [blame] | 42 | #include "../include/obd_class.h" |
| 43 | #include "../include/lustre/lustre_idl.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 44 | |
| 45 | #include "lov_internal.h" |
| 46 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 47 | static int lsm_lmm_verify_common(struct lov_mds_md *lmm, int lmm_bytes, |
| 48 | __u16 stripe_count) |
| 49 | { |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 50 | if (stripe_count > LOV_V1_INSANE_STRIPE_COUNT) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 51 | CERROR("bad stripe count %d\n", stripe_count); |
Andreas Dilger | 53b7853 | 2013-06-03 21:40:47 +0800 | [diff] [blame] | 52 | lov_dump_lmm_common(D_WARNING, lmm); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 53 | return -EINVAL; |
| 54 | } |
| 55 | |
| 56 | if (lmm_oi_id(&lmm->lmm_oi) == 0) { |
| 57 | CERROR("zero object id\n"); |
Andreas Dilger | 53b7853 | 2013-06-03 21:40:47 +0800 | [diff] [blame] | 58 | lov_dump_lmm_common(D_WARNING, lmm); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 59 | return -EINVAL; |
| 60 | } |
| 61 | |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 62 | if (lov_pattern(le32_to_cpu(lmm->lmm_pattern)) != LOV_PATTERN_RAID0) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 63 | CERROR("bad striping pattern\n"); |
Andreas Dilger | 53b7853 | 2013-06-03 21:40:47 +0800 | [diff] [blame] | 64 | lov_dump_lmm_common(D_WARNING, lmm); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 65 | return -EINVAL; |
| 66 | } |
| 67 | |
| 68 | if (lmm->lmm_stripe_size == 0 || |
Oleg Drokin | cd94f23 | 2016-08-21 18:04:34 -0400 | [diff] [blame] | 69 | (le32_to_cpu(lmm->lmm_stripe_size) & |
| 70 | (LOV_MIN_STRIPE_SIZE - 1)) != 0) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 71 | CERROR("bad stripe size %u\n", |
| 72 | le32_to_cpu(lmm->lmm_stripe_size)); |
Andreas Dilger | 53b7853 | 2013-06-03 21:40:47 +0800 | [diff] [blame] | 73 | lov_dump_lmm_common(D_WARNING, lmm); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 74 | return -EINVAL; |
| 75 | } |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | struct lov_stripe_md *lsm_alloc_plain(__u16 stripe_count, int *size) |
| 80 | { |
| 81 | struct lov_stripe_md *lsm; |
| 82 | struct lov_oinfo *loi; |
| 83 | int i, oinfo_ptrs_size; |
| 84 | |
| 85 | LASSERT(stripe_count <= LOV_MAX_STRIPE_COUNT); |
| 86 | |
| 87 | oinfo_ptrs_size = sizeof(struct lov_oinfo *) * stripe_count; |
| 88 | *size = sizeof(struct lov_stripe_md) + oinfo_ptrs_size; |
| 89 | |
Julia Lawall | 3d0ba71 | 2015-06-11 14:02:54 +0200 | [diff] [blame] | 90 | lsm = libcfs_kvzalloc(*size, GFP_NOFS); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 91 | if (!lsm) |
Monam Agarwal | 76b8f53 | 2014-03-01 17:03:33 +0530 | [diff] [blame] | 92 | return NULL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 93 | |
| 94 | for (i = 0; i < stripe_count; i++) { |
Amitoj Kaur Chawla | 8210132 | 2016-02-26 14:24:35 +0530 | [diff] [blame] | 95 | loi = kmem_cache_zalloc(lov_oinfo_slab, GFP_NOFS); |
Oleg Drokin | 00697c4 | 2016-02-16 00:46:45 -0500 | [diff] [blame] | 96 | if (!loi) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 97 | goto err; |
| 98 | lsm->lsm_oinfo[i] = loi; |
| 99 | } |
| 100 | lsm->lsm_stripe_count = stripe_count; |
| 101 | return lsm; |
| 102 | |
| 103 | err: |
| 104 | while (--i >= 0) |
Mike Rapoport | 5c4d8ed | 2015-10-20 12:39:52 +0300 | [diff] [blame] | 105 | kmem_cache_free(lov_oinfo_slab, lsm->lsm_oinfo[i]); |
Julia Lawall | 3d0ba71 | 2015-06-11 14:02:54 +0200 | [diff] [blame] | 106 | kvfree(lsm); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 107 | return NULL; |
| 108 | } |
| 109 | |
| 110 | void lsm_free_plain(struct lov_stripe_md *lsm) |
| 111 | { |
| 112 | __u16 stripe_count = lsm->lsm_stripe_count; |
| 113 | int i; |
| 114 | |
| 115 | for (i = 0; i < stripe_count; i++) |
Mike Rapoport | 5c4d8ed | 2015-10-20 12:39:52 +0300 | [diff] [blame] | 116 | kmem_cache_free(lov_oinfo_slab, lsm->lsm_oinfo[i]); |
Julia Lawall | 3d0ba71 | 2015-06-11 14:02:54 +0200 | [diff] [blame] | 117 | kvfree(lsm); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static void lsm_unpackmd_common(struct lov_stripe_md *lsm, |
| 121 | struct lov_mds_md *lmm) |
| 122 | { |
| 123 | /* |
| 124 | * This supposes lov_mds_md_v1/v3 first fields are |
| 125 | * are the same |
| 126 | */ |
| 127 | lmm_oi_le_to_cpu(&lsm->lsm_oi, &lmm->lmm_oi); |
| 128 | lsm->lsm_stripe_size = le32_to_cpu(lmm->lmm_stripe_size); |
| 129 | lsm->lsm_pattern = le32_to_cpu(lmm->lmm_pattern); |
| 130 | lsm->lsm_layout_gen = le16_to_cpu(lmm->lmm_layout_gen); |
| 131 | lsm->lsm_pool_name[0] = '\0'; |
| 132 | } |
| 133 | |
| 134 | static void |
| 135 | lsm_stripe_by_index_plain(struct lov_stripe_md *lsm, int *stripeno, |
Oleg Drokin | f1564f1 | 2016-02-26 01:50:05 -0500 | [diff] [blame] | 136 | u64 *lov_off, u64 *swidth) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 137 | { |
| 138 | if (swidth) |
Oleg Drokin | 21aef7d | 2014-08-15 12:55:56 -0400 | [diff] [blame] | 139 | *swidth = (u64)lsm->lsm_stripe_size * lsm->lsm_stripe_count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void |
| 143 | lsm_stripe_by_offset_plain(struct lov_stripe_md *lsm, int *stripeno, |
Oleg Drokin | 21aef7d | 2014-08-15 12:55:56 -0400 | [diff] [blame] | 144 | u64 *lov_off, u64 *swidth) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 145 | { |
| 146 | if (swidth) |
Oleg Drokin | 21aef7d | 2014-08-15 12:55:56 -0400 | [diff] [blame] | 147 | *swidth = (u64)lsm->lsm_stripe_size * lsm->lsm_stripe_count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 148 | } |
| 149 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 150 | /* Find minimum stripe maxbytes value. For inactive or |
John L. Hammond | b9d4b14 | 2016-09-18 16:37:39 -0400 | [diff] [blame] | 151 | * reconnecting targets use LUSTRE_EXT3_STRIPE_MAXBYTES. |
Oleg Drokin | acb9abc | 2016-02-24 22:00:32 -0500 | [diff] [blame] | 152 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 153 | static void lov_tgt_maxbytes(struct lov_tgt_desc *tgt, __u64 *stripe_maxbytes) |
| 154 | { |
| 155 | struct obd_import *imp = tgt->ltd_obd->u.cli.cl_import; |
| 156 | |
Oleg Drokin | 00697c4 | 2016-02-16 00:46:45 -0500 | [diff] [blame] | 157 | if (!imp || !tgt->ltd_active) { |
John L. Hammond | b9d4b14 | 2016-09-18 16:37:39 -0400 | [diff] [blame] | 158 | *stripe_maxbytes = LUSTRE_EXT3_STRIPE_MAXBYTES; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | |
| 162 | spin_lock(&imp->imp_lock); |
| 163 | if (imp->imp_state == LUSTRE_IMP_FULL && |
| 164 | (imp->imp_connect_data.ocd_connect_flags & OBD_CONNECT_MAXBYTES) && |
| 165 | imp->imp_connect_data.ocd_maxbytes > 0) { |
| 166 | if (*stripe_maxbytes > imp->imp_connect_data.ocd_maxbytes) |
| 167 | *stripe_maxbytes = imp->imp_connect_data.ocd_maxbytes; |
| 168 | } else { |
John L. Hammond | b9d4b14 | 2016-09-18 16:37:39 -0400 | [diff] [blame] | 169 | *stripe_maxbytes = LUSTRE_EXT3_STRIPE_MAXBYTES; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 170 | } |
| 171 | spin_unlock(&imp->imp_lock); |
| 172 | } |
| 173 | |
| 174 | static int lsm_lmm_verify_v1(struct lov_mds_md_v1 *lmm, int lmm_bytes, |
| 175 | __u16 *stripe_count) |
| 176 | { |
| 177 | if (lmm_bytes < sizeof(*lmm)) { |
| 178 | CERROR("lov_mds_md_v1 too small: %d, need at least %d\n", |
| 179 | lmm_bytes, (int)sizeof(*lmm)); |
| 180 | return -EINVAL; |
| 181 | } |
| 182 | |
| 183 | *stripe_count = le16_to_cpu(lmm->lmm_stripe_count); |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 184 | if (le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED) |
| 185 | *stripe_count = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 186 | |
| 187 | if (lmm_bytes < lov_mds_md_size(*stripe_count, LOV_MAGIC_V1)) { |
| 188 | CERROR("LOV EA V1 too small: %d, need %d\n", |
| 189 | lmm_bytes, lov_mds_md_size(*stripe_count, LOV_MAGIC_V1)); |
Andreas Dilger | 53b7853 | 2013-06-03 21:40:47 +0800 | [diff] [blame] | 190 | lov_dump_lmm_common(D_WARNING, lmm); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 191 | return -EINVAL; |
| 192 | } |
| 193 | |
| 194 | return lsm_lmm_verify_common(lmm, lmm_bytes, *stripe_count); |
| 195 | } |
| 196 | |
Le Tan | 12e397c | 2015-02-11 12:13:14 +0800 | [diff] [blame] | 197 | static int lsm_unpackmd_v1(struct lov_obd *lov, struct lov_stripe_md *lsm, |
| 198 | struct lov_mds_md_v1 *lmm) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 199 | { |
| 200 | struct lov_oinfo *loi; |
| 201 | int i; |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 202 | int stripe_count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 203 | __u64 stripe_maxbytes = OBD_OBJECT_EOF; |
| 204 | |
| 205 | lsm_unpackmd_common(lsm, lmm); |
| 206 | |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 207 | stripe_count = lsm_is_released(lsm) ? 0 : lsm->lsm_stripe_count; |
| 208 | |
| 209 | for (i = 0; i < stripe_count; i++) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 210 | /* XXX LOV STACKING call down to osc_unpackmd() */ |
| 211 | loi = lsm->lsm_oinfo[i]; |
| 212 | ostid_le_to_cpu(&lmm->lmm_objects[i].l_ost_oi, &loi->loi_oi); |
| 213 | loi->loi_ost_idx = le32_to_cpu(lmm->lmm_objects[i].l_ost_idx); |
| 214 | loi->loi_ost_gen = le32_to_cpu(lmm->lmm_objects[i].l_ost_gen); |
Yang Sheng | 397632e | 2015-03-25 21:53:22 -0400 | [diff] [blame] | 215 | if (lov_oinfo_is_dummy(loi)) |
| 216 | continue; |
| 217 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 218 | if (loi->loi_ost_idx >= lov->desc.ld_tgt_count) { |
| 219 | CERROR("OST index %d more than OST count %d\n", |
| 220 | loi->loi_ost_idx, lov->desc.ld_tgt_count); |
| 221 | lov_dump_lmm_v1(D_WARNING, lmm); |
| 222 | return -EINVAL; |
| 223 | } |
| 224 | if (!lov->lov_tgts[loi->loi_ost_idx]) { |
| 225 | CERROR("OST index %d missing\n", loi->loi_ost_idx); |
| 226 | lov_dump_lmm_v1(D_WARNING, lmm); |
| 227 | return -EINVAL; |
| 228 | } |
| 229 | /* calculate the minimum stripe max bytes */ |
| 230 | lov_tgt_maxbytes(lov->lov_tgts[loi->loi_ost_idx], |
| 231 | &stripe_maxbytes); |
| 232 | } |
| 233 | |
| 234 | lsm->lsm_maxbytes = stripe_maxbytes * lsm->lsm_stripe_count; |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 235 | if (lsm->lsm_stripe_count == 0) |
| 236 | lsm->lsm_maxbytes = stripe_maxbytes * lov->desc.ld_tgt_count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | const struct lsm_operations lsm_v1_ops = { |
| 242 | .lsm_free = lsm_free_plain, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 243 | .lsm_stripe_by_index = lsm_stripe_by_index_plain, |
| 244 | .lsm_stripe_by_offset = lsm_stripe_by_offset_plain, |
| 245 | .lsm_lmm_verify = lsm_lmm_verify_v1, |
| 246 | .lsm_unpackmd = lsm_unpackmd_v1, |
| 247 | }; |
| 248 | |
| 249 | static int lsm_lmm_verify_v3(struct lov_mds_md *lmmv1, int lmm_bytes, |
| 250 | __u16 *stripe_count) |
| 251 | { |
| 252 | struct lov_mds_md_v3 *lmm; |
| 253 | |
| 254 | lmm = (struct lov_mds_md_v3 *)lmmv1; |
| 255 | |
| 256 | if (lmm_bytes < sizeof(*lmm)) { |
| 257 | CERROR("lov_mds_md_v3 too small: %d, need at least %d\n", |
| 258 | lmm_bytes, (int)sizeof(*lmm)); |
| 259 | return -EINVAL; |
| 260 | } |
| 261 | |
| 262 | *stripe_count = le16_to_cpu(lmm->lmm_stripe_count); |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 263 | if (le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED) |
| 264 | *stripe_count = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 265 | |
| 266 | if (lmm_bytes < lov_mds_md_size(*stripe_count, LOV_MAGIC_V3)) { |
| 267 | CERROR("LOV EA V3 too small: %d, need %d\n", |
| 268 | lmm_bytes, lov_mds_md_size(*stripe_count, LOV_MAGIC_V3)); |
Andreas Dilger | 53b7853 | 2013-06-03 21:40:47 +0800 | [diff] [blame] | 269 | lov_dump_lmm_common(D_WARNING, lmm); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 270 | return -EINVAL; |
| 271 | } |
| 272 | |
| 273 | return lsm_lmm_verify_common((struct lov_mds_md_v1 *)lmm, lmm_bytes, |
| 274 | *stripe_count); |
| 275 | } |
| 276 | |
Le Tan | 12e397c | 2015-02-11 12:13:14 +0800 | [diff] [blame] | 277 | static int lsm_unpackmd_v3(struct lov_obd *lov, struct lov_stripe_md *lsm, |
| 278 | struct lov_mds_md *lmmv1) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 279 | { |
| 280 | struct lov_mds_md_v3 *lmm; |
| 281 | struct lov_oinfo *loi; |
| 282 | int i; |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 283 | int stripe_count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 284 | __u64 stripe_maxbytes = OBD_OBJECT_EOF; |
| 285 | int cplen = 0; |
| 286 | |
| 287 | lmm = (struct lov_mds_md_v3 *)lmmv1; |
| 288 | |
| 289 | lsm_unpackmd_common(lsm, (struct lov_mds_md_v1 *)lmm); |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 290 | |
| 291 | stripe_count = lsm_is_released(lsm) ? 0 : lsm->lsm_stripe_count; |
| 292 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 293 | cplen = strlcpy(lsm->lsm_pool_name, lmm->lmm_pool_name, |
| 294 | sizeof(lsm->lsm_pool_name)); |
| 295 | if (cplen >= sizeof(lsm->lsm_pool_name)) |
| 296 | return -E2BIG; |
| 297 | |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 298 | for (i = 0; i < stripe_count; i++) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 299 | /* XXX LOV STACKING call down to osc_unpackmd() */ |
| 300 | loi = lsm->lsm_oinfo[i]; |
| 301 | ostid_le_to_cpu(&lmm->lmm_objects[i].l_ost_oi, &loi->loi_oi); |
| 302 | loi->loi_ost_idx = le32_to_cpu(lmm->lmm_objects[i].l_ost_idx); |
| 303 | loi->loi_ost_gen = le32_to_cpu(lmm->lmm_objects[i].l_ost_gen); |
Yang Sheng | 397632e | 2015-03-25 21:53:22 -0400 | [diff] [blame] | 304 | if (lov_oinfo_is_dummy(loi)) |
| 305 | continue; |
| 306 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 307 | if (loi->loi_ost_idx >= lov->desc.ld_tgt_count) { |
| 308 | CERROR("OST index %d more than OST count %d\n", |
| 309 | loi->loi_ost_idx, lov->desc.ld_tgt_count); |
| 310 | lov_dump_lmm_v3(D_WARNING, lmm); |
| 311 | return -EINVAL; |
| 312 | } |
| 313 | if (!lov->lov_tgts[loi->loi_ost_idx]) { |
| 314 | CERROR("OST index %d missing\n", loi->loi_ost_idx); |
| 315 | lov_dump_lmm_v3(D_WARNING, lmm); |
| 316 | return -EINVAL; |
| 317 | } |
| 318 | /* calculate the minimum stripe max bytes */ |
| 319 | lov_tgt_maxbytes(lov->lov_tgts[loi->loi_ost_idx], |
| 320 | &stripe_maxbytes); |
| 321 | } |
| 322 | |
| 323 | lsm->lsm_maxbytes = stripe_maxbytes * lsm->lsm_stripe_count; |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 324 | if (lsm->lsm_stripe_count == 0) |
| 325 | lsm->lsm_maxbytes = stripe_maxbytes * lov->desc.ld_tgt_count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | const struct lsm_operations lsm_v3_ops = { |
| 331 | .lsm_free = lsm_free_plain, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 332 | .lsm_stripe_by_index = lsm_stripe_by_index_plain, |
| 333 | .lsm_stripe_by_offset = lsm_stripe_by_offset_plain, |
| 334 | .lsm_lmm_verify = lsm_lmm_verify_v3, |
| 335 | .lsm_unpackmd = lsm_unpackmd_v3, |
| 336 | }; |
John L. Hammond | 081b726 | 2014-04-27 13:06:40 -0400 | [diff] [blame] | 337 | |
| 338 | void dump_lsm(unsigned int level, const struct lov_stripe_md *lsm) |
| 339 | { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 340 | CDEBUG(level, "lsm %p, objid " DOSTID ", maxbytes %#llx, magic 0x%08X, stripe_size %u, stripe_count %u, refc: %d, layout_gen %u, pool [" LOV_POOLNAMEF "]\n", |
| 341 | lsm, |
John L. Hammond | 081b726 | 2014-04-27 13:06:40 -0400 | [diff] [blame] | 342 | POSTID(&lsm->lsm_oi), lsm->lsm_maxbytes, lsm->lsm_magic, |
| 343 | lsm->lsm_stripe_size, lsm->lsm_stripe_count, |
| 344 | atomic_read(&lsm->lsm_refc), lsm->lsm_layout_gen, |
| 345 | lsm->lsm_pool_name); |
| 346 | } |