]>
Commit | Line | Data |
---|---|---|
d7e09d03 PT |
1 | /* |
2 | * GPL HEADER START | |
3 | * | |
4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 only, | |
8 | * as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License version 2 for more details (a copy is included | |
14 | * in the LICENSE file that accompanied this code). | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * version 2 along with this program; If not, see | |
18 | * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf | |
19 | * | |
20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
21 | * CA 95054 USA or visit www.sun.com if you need additional information or | |
22 | * have any questions. | |
23 | * | |
24 | * GPL HEADER END | |
25 | */ | |
26 | /* | |
27 | * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
30 | * Copyright (c) 2011, 2012, Intel Corporation. | |
31 | */ | |
32 | /* | |
33 | * This file is part of Lustre, http://www.lustre.org/ | |
34 | * Lustre is a trademark of Sun Microsystems, Inc. | |
35 | * | |
36 | * lustre/lov/lov_obd.c | |
37 | * | |
38 | * Author: Phil Schwan <phil@clusterfs.com> | |
39 | * Author: Peter Braam <braam@clusterfs.com> | |
40 | * Author: Mike Shaver <shaver@clusterfs.com> | |
41 | * Author: Nathan Rutman <nathan@clusterfs.com> | |
42 | */ | |
43 | ||
44 | #define DEBUG_SUBSYSTEM S_LOV | |
9fdaf8c0 | 45 | #include "../../include/linux/libcfs/libcfs.h" |
d7e09d03 | 46 | |
0cf0f7a7 GKH |
47 | #include "../include/obd_support.h" |
48 | #include "../include/lustre_lib.h" | |
49 | #include "../include/lustre_net.h" | |
50 | #include "../include/lustre/lustre_idl.h" | |
51 | #include "../include/lustre_dlm.h" | |
52 | #include "../include/lustre_mds.h" | |
53 | #include "../include/obd_class.h" | |
0cf0f7a7 GKH |
54 | #include "../include/lprocfs_status.h" |
55 | #include "../include/lustre_param.h" | |
56 | #include "../include/cl_object.h" | |
57 | #include "../include/lclient.h" /* for cl_client_lru */ | |
58 | #include "../include/lustre/ll_fiemap.h" | |
59 | #include "../include/lustre_fid.h" | |
d7e09d03 PT |
60 | |
61 | #include "lov_internal.h" | |
62 | ||
63 | /* Keep a refcount of lov->tgt usage to prevent racing with addition/deletion. | |
64 | Any function that expects lov_tgts to remain stationary must take a ref. */ | |
65 | static void lov_getref(struct obd_device *obd) | |
66 | { | |
67 | struct lov_obd *lov = &obd->u.lov; | |
68 | ||
69 | /* nobody gets through here until lov_putref is done */ | |
70 | mutex_lock(&lov->lov_lock); | |
71 | atomic_inc(&lov->lov_refcount); | |
72 | mutex_unlock(&lov->lov_lock); | |
73 | return; | |
74 | } | |
75 | ||
76 | static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt); | |
77 | ||
78 | static void lov_putref(struct obd_device *obd) | |
79 | { | |
80 | struct lov_obd *lov = &obd->u.lov; | |
81 | ||
82 | mutex_lock(&lov->lov_lock); | |
83 | /* ok to dec to 0 more than once -- ltd_exp's will be null */ | |
84 | if (atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) { | |
85 | LIST_HEAD(kill); | |
86 | int i; | |
87 | struct lov_tgt_desc *tgt, *n; | |
88 | CDEBUG(D_CONFIG, "destroying %d lov targets\n", | |
89 | lov->lov_death_row); | |
90 | for (i = 0; i < lov->desc.ld_tgt_count; i++) { | |
91 | tgt = lov->lov_tgts[i]; | |
92 | ||
93 | if (!tgt || !tgt->ltd_reap) | |
94 | continue; | |
95 | list_add(&tgt->ltd_kill, &kill); | |
96 | /* XXX - right now there is a dependency on ld_tgt_count | |
97 | * being the maximum tgt index for computing the | |
98 | * mds_max_easize. So we can't shrink it. */ | |
99 | lov_ost_pool_remove(&lov->lov_packed, i); | |
100 | lov->lov_tgts[i] = NULL; | |
101 | lov->lov_death_row--; | |
102 | } | |
103 | mutex_unlock(&lov->lov_lock); | |
104 | ||
105 | list_for_each_entry_safe(tgt, n, &kill, ltd_kill) { | |
106 | list_del(&tgt->ltd_kill); | |
107 | /* Disconnect */ | |
108 | __lov_del_obd(obd, tgt); | |
109 | } | |
110 | } else { | |
111 | mutex_unlock(&lov->lov_lock); | |
112 | } | |
113 | } | |
114 | ||
115 | static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid, | |
116 | enum obd_notify_event ev); | |
117 | static int lov_notify(struct obd_device *obd, struct obd_device *watched, | |
118 | enum obd_notify_event ev, void *data); | |
119 | ||
120 | ||
121 | #define MAX_STRING_SIZE 128 | |
122 | int lov_connect_obd(struct obd_device *obd, __u32 index, int activate, | |
123 | struct obd_connect_data *data) | |
124 | { | |
125 | struct lov_obd *lov = &obd->u.lov; | |
126 | struct obd_uuid *tgt_uuid; | |
127 | struct obd_device *tgt_obd; | |
128 | static struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" }; | |
129 | struct obd_import *imp; | |
b59fe845 | 130 | struct proc_dir_entry *lov_proc_dir; |
d7e09d03 | 131 | int rc; |
d7e09d03 PT |
132 | |
133 | if (!lov->lov_tgts[index]) | |
0a3bdb00 | 134 | return -EINVAL; |
d7e09d03 PT |
135 | |
136 | tgt_uuid = &lov->lov_tgts[index]->ltd_uuid; | |
137 | tgt_obd = lov->lov_tgts[index]->ltd_obd; | |
138 | ||
139 | if (!tgt_obd->obd_set_up) { | |
140 | CERROR("Target %s not set up\n", obd_uuid2str(tgt_uuid)); | |
0a3bdb00 | 141 | return -EINVAL; |
d7e09d03 PT |
142 | } |
143 | ||
144 | /* override the sp_me from lov */ | |
145 | tgt_obd->u.cli.cl_sp_me = lov->lov_sp_me; | |
146 | ||
147 | if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX)) | |
148 | data->ocd_index = index; | |
149 | ||
150 | /* | |
151 | * Divine LOV knows that OBDs under it are OSCs. | |
152 | */ | |
153 | imp = tgt_obd->u.cli.cl_import; | |
154 | ||
155 | if (activate) { | |
156 | tgt_obd->obd_no_recov = 0; | |
157 | /* FIXME this is probably supposed to be | |
158 | ptlrpc_set_import_active. Horrible naming. */ | |
159 | ptlrpc_activate_import(imp); | |
160 | } | |
161 | ||
162 | rc = obd_register_observer(tgt_obd, obd); | |
163 | if (rc) { | |
164 | CERROR("Target %s register_observer error %d\n", | |
165 | obd_uuid2str(tgt_uuid), rc); | |
0a3bdb00 | 166 | return rc; |
d7e09d03 PT |
167 | } |
168 | ||
169 | ||
170 | if (imp->imp_invalid) { | |
171 | CDEBUG(D_CONFIG, "not connecting OSC %s; administratively " | |
172 | "disabled\n", obd_uuid2str(tgt_uuid)); | |
0a3bdb00 | 173 | return 0; |
d7e09d03 PT |
174 | } |
175 | ||
176 | rc = obd_connect(NULL, &lov->lov_tgts[index]->ltd_exp, tgt_obd, | |
177 | &lov_osc_uuid, data, NULL); | |
178 | if (rc || !lov->lov_tgts[index]->ltd_exp) { | |
179 | CERROR("Target %s connect error %d\n", | |
180 | obd_uuid2str(tgt_uuid), rc); | |
0a3bdb00 | 181 | return -ENODEV; |
d7e09d03 PT |
182 | } |
183 | ||
184 | lov->lov_tgts[index]->ltd_reap = 0; | |
185 | ||
186 | CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index, | |
187 | obd_uuid2str(tgt_uuid), tgt_obd->obd_name, activate ? "":"in"); | |
188 | ||
73bb1da6 | 189 | lov_proc_dir = obd->obd_proc_private; |
d7e09d03 PT |
190 | if (lov_proc_dir) { |
191 | struct obd_device *osc_obd = lov->lov_tgts[index]->ltd_exp->exp_obd; | |
b59fe845 | 192 | struct proc_dir_entry *osc_symlink; |
d7e09d03 PT |
193 | |
194 | LASSERT(osc_obd != NULL); | |
195 | LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC); | |
196 | LASSERT(osc_obd->obd_type->typ_name != NULL); | |
197 | ||
198 | osc_symlink = lprocfs_add_symlink(osc_obd->obd_name, | |
199 | lov_proc_dir, | |
200 | "../../../%s/%s", | |
201 | osc_obd->obd_type->typ_name, | |
202 | osc_obd->obd_name); | |
203 | if (osc_symlink == NULL) { | |
204 | CERROR("could not register LOV target " | |
205 | "/proc/fs/lustre/%s/%s/target_obds/%s.", | |
206 | obd->obd_type->typ_name, obd->obd_name, | |
207 | osc_obd->obd_name); | |
208 | lprocfs_remove(&lov_proc_dir); | |
73bb1da6 | 209 | obd->obd_proc_private = NULL; |
d7e09d03 PT |
210 | } |
211 | } | |
212 | ||
0a3bdb00 | 213 | return 0; |
d7e09d03 PT |
214 | } |
215 | ||
216 | static int lov_connect(const struct lu_env *env, | |
217 | struct obd_export **exp, struct obd_device *obd, | |
218 | struct obd_uuid *cluuid, struct obd_connect_data *data, | |
219 | void *localdata) | |
220 | { | |
221 | struct lov_obd *lov = &obd->u.lov; | |
222 | struct lov_tgt_desc *tgt; | |
223 | struct lustre_handle conn; | |
224 | int i, rc; | |
d7e09d03 PT |
225 | |
226 | CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects); | |
227 | ||
228 | rc = class_connect(&conn, obd, cluuid); | |
229 | if (rc) | |
0a3bdb00 | 230 | return rc; |
d7e09d03 PT |
231 | |
232 | *exp = class_conn2export(&conn); | |
233 | ||
234 | /* Why should there ever be more than 1 connect? */ | |
235 | lov->lov_connects++; | |
236 | LASSERT(lov->lov_connects == 1); | |
237 | ||
238 | memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd)); | |
239 | if (data) | |
240 | lov->lov_ocd = *data; | |
241 | ||
242 | obd_getref(obd); | |
243 | for (i = 0; i < lov->desc.ld_tgt_count; i++) { | |
244 | tgt = lov->lov_tgts[i]; | |
245 | if (!tgt || obd_uuid_empty(&tgt->ltd_uuid)) | |
246 | continue; | |
247 | /* Flags will be lowest common denominator */ | |
248 | rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd); | |
249 | if (rc) { | |
250 | CERROR("%s: lov connect tgt %d failed: %d\n", | |
251 | obd->obd_name, i, rc); | |
252 | continue; | |
253 | } | |
254 | /* connect to administrative disabled ost */ | |
255 | if (!lov->lov_tgts[i]->ltd_exp) | |
256 | continue; | |
257 | ||
258 | rc = lov_notify(obd, lov->lov_tgts[i]->ltd_exp->exp_obd, | |
259 | OBD_NOTIFY_CONNECT, (void *)&i); | |
260 | if (rc) { | |
261 | CERROR("%s error sending notify %d\n", | |
262 | obd->obd_name, rc); | |
263 | } | |
264 | } | |
265 | obd_putref(obd); | |
266 | ||
0a3bdb00 | 267 | return 0; |
d7e09d03 PT |
268 | } |
269 | ||
270 | static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt) | |
271 | { | |
b59fe845 | 272 | struct proc_dir_entry *lov_proc_dir; |
d7e09d03 PT |
273 | struct lov_obd *lov = &obd->u.lov; |
274 | struct obd_device *osc_obd; | |
275 | int rc; | |
d7e09d03 PT |
276 | |
277 | osc_obd = class_exp2obd(tgt->ltd_exp); | |
278 | CDEBUG(D_CONFIG, "%s: disconnecting target %s\n", | |
3456a40e | 279 | obd->obd_name, osc_obd ? osc_obd->obd_name : "NULL"); |
d7e09d03 PT |
280 | |
281 | if (tgt->ltd_active) { | |
282 | tgt->ltd_active = 0; | |
283 | lov->desc.ld_active_tgt_count--; | |
284 | tgt->ltd_exp->exp_obd->obd_inactive = 1; | |
285 | } | |
286 | ||
d7e09d03 | 287 | if (osc_obd) { |
3456a40e RS |
288 | lov_proc_dir = obd->obd_proc_private; |
289 | if (lov_proc_dir) { | |
290 | lprocfs_remove_proc_entry(osc_obd->obd_name, lov_proc_dir); | |
291 | } | |
d7e09d03 PT |
292 | /* Pass it on to our clients. |
293 | * XXX This should be an argument to disconnect, | |
294 | * XXX not a back-door flag on the OBD. Ah well. | |
295 | */ | |
296 | osc_obd->obd_force = obd->obd_force; | |
297 | osc_obd->obd_fail = obd->obd_fail; | |
298 | osc_obd->obd_no_recov = obd->obd_no_recov; | |
299 | } | |
300 | ||
301 | obd_register_observer(osc_obd, NULL); | |
302 | ||
303 | rc = obd_disconnect(tgt->ltd_exp); | |
304 | if (rc) { | |
305 | CERROR("Target %s disconnect error %d\n", | |
306 | tgt->ltd_uuid.uuid, rc); | |
307 | rc = 0; | |
308 | } | |
309 | ||
310 | tgt->ltd_exp = NULL; | |
0a3bdb00 | 311 | return 0; |
d7e09d03 PT |
312 | } |
313 | ||
314 | static int lov_disconnect(struct obd_export *exp) | |
315 | { | |
316 | struct obd_device *obd = class_exp2obd(exp); | |
317 | struct lov_obd *lov = &obd->u.lov; | |
318 | int i, rc; | |
d7e09d03 PT |
319 | |
320 | if (!lov->lov_tgts) | |
321 | goto out; | |
322 | ||
323 | /* Only disconnect the underlying layers on the final disconnect. */ | |
324 | lov->lov_connects--; | |
325 | if (lov->lov_connects != 0) { | |
326 | /* why should there be more than 1 connect? */ | |
327 | CERROR("disconnect #%d\n", lov->lov_connects); | |
328 | goto out; | |
329 | } | |
330 | ||
331 | /* Let's hold another reference so lov_del_obd doesn't spin through | |
332 | putref every time */ | |
333 | obd_getref(obd); | |
334 | ||
335 | for (i = 0; i < lov->desc.ld_tgt_count; i++) { | |
336 | if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) { | |
337 | /* Disconnection is the last we know about an obd */ | |
2046a81d | 338 | lov_del_target(obd, i, NULL, lov->lov_tgts[i]->ltd_gen); |
d7e09d03 PT |
339 | } |
340 | } | |
341 | obd_putref(obd); | |
342 | ||
343 | out: | |
344 | rc = class_disconnect(exp); /* bz 9811 */ | |
0a3bdb00 | 345 | return rc; |
d7e09d03 PT |
346 | } |
347 | ||
348 | /* Error codes: | |
349 | * | |
350 | * -EINVAL : UUID can't be found in the LOV's target list | |
351 | * -ENOTCONN: The UUID is found, but the target connection is bad (!) | |
352 | * -EBADF : The UUID is found, but the OBD is the wrong type (!) | |
353 | * any >= 0 : is log target index | |
354 | */ | |
355 | static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid, | |
356 | enum obd_notify_event ev) | |
357 | { | |
358 | struct lov_obd *lov = &obd->u.lov; | |
359 | struct lov_tgt_desc *tgt; | |
360 | int index, activate, active; | |
d7e09d03 PT |
361 | |
362 | CDEBUG(D_INFO, "Searching in lov %p for uuid %s event(%d)\n", | |
363 | lov, uuid->uuid, ev); | |
364 | ||
365 | obd_getref(obd); | |
366 | for (index = 0; index < lov->desc.ld_tgt_count; index++) { | |
367 | tgt = lov->lov_tgts[index]; | |
368 | if (!tgt) | |
369 | continue; | |
370 | /* | |
371 | * LU-642, initially inactive OSC could miss the obd_connect, | |
372 | * we make up for it here. | |
373 | */ | |
374 | if (ev == OBD_NOTIFY_ACTIVATE && tgt->ltd_exp == NULL && | |
375 | obd_uuid_equals(uuid, &tgt->ltd_uuid)) { | |
376 | struct obd_uuid lov_osc_uuid = {"LOV_OSC_UUID"}; | |
377 | ||
378 | obd_connect(NULL, &tgt->ltd_exp, tgt->ltd_obd, | |
379 | &lov_osc_uuid, &lov->lov_ocd, NULL); | |
380 | } | |
381 | if (!tgt->ltd_exp) | |
382 | continue; | |
383 | ||
55f5a824 | 384 | CDEBUG(D_INFO, "lov idx %d is %s conn %#llx\n", |
d7e09d03 PT |
385 | index, obd_uuid2str(&tgt->ltd_uuid), |
386 | tgt->ltd_exp->exp_handle.h_cookie); | |
387 | if (obd_uuid_equals(uuid, &tgt->ltd_uuid)) | |
388 | break; | |
389 | } | |
390 | ||
18751668 JL |
391 | if (index == lov->desc.ld_tgt_count) { |
392 | index = -EINVAL; | |
393 | goto out; | |
394 | } | |
d7e09d03 PT |
395 | |
396 | if (ev == OBD_NOTIFY_DEACTIVATE || ev == OBD_NOTIFY_ACTIVATE) { | |
397 | activate = (ev == OBD_NOTIFY_ACTIVATE) ? 1 : 0; | |
398 | ||
399 | if (lov->lov_tgts[index]->ltd_activate == activate) { | |
400 | CDEBUG(D_INFO, "OSC %s already %sactivate!\n", | |
401 | uuid->uuid, activate ? "" : "de"); | |
402 | } else { | |
403 | lov->lov_tgts[index]->ltd_activate = activate; | |
404 | CDEBUG(D_CONFIG, "%sactivate OSC %s\n", | |
405 | activate ? "" : "de", obd_uuid2str(uuid)); | |
406 | } | |
407 | ||
408 | } else if (ev == OBD_NOTIFY_INACTIVE || ev == OBD_NOTIFY_ACTIVE) { | |
409 | active = (ev == OBD_NOTIFY_ACTIVE) ? 1 : 0; | |
410 | ||
411 | if (lov->lov_tgts[index]->ltd_active == active) { | |
412 | CDEBUG(D_INFO, "OSC %s already %sactive!\n", | |
413 | uuid->uuid, active ? "" : "in"); | |
18751668 | 414 | goto out; |
d7e09d03 PT |
415 | } else { |
416 | CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", | |
417 | obd_uuid2str(uuid), active ? "" : "in"); | |
418 | } | |
419 | ||
420 | lov->lov_tgts[index]->ltd_active = active; | |
421 | if (active) { | |
422 | lov->desc.ld_active_tgt_count++; | |
423 | lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0; | |
424 | } else { | |
425 | lov->desc.ld_active_tgt_count--; | |
426 | lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1; | |
427 | } | |
428 | } else { | |
429 | CERROR("Unknown event(%d) for uuid %s", ev, uuid->uuid); | |
430 | } | |
431 | ||
432 | out: | |
433 | obd_putref(obd); | |
0a3bdb00 | 434 | return index; |
d7e09d03 PT |
435 | } |
436 | ||
437 | static int lov_notify(struct obd_device *obd, struct obd_device *watched, | |
438 | enum obd_notify_event ev, void *data) | |
439 | { | |
440 | int rc = 0; | |
441 | struct lov_obd *lov = &obd->u.lov; | |
d7e09d03 PT |
442 | |
443 | down_read(&lov->lov_notify_lock); | |
444 | if (!lov->lov_connects) { | |
445 | up_read(&lov->lov_notify_lock); | |
0a3bdb00 | 446 | return rc; |
d7e09d03 PT |
447 | } |
448 | ||
449 | if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE || | |
450 | ev == OBD_NOTIFY_ACTIVATE || ev == OBD_NOTIFY_DEACTIVATE) { | |
451 | struct obd_uuid *uuid; | |
452 | ||
453 | LASSERT(watched); | |
454 | ||
455 | if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) { | |
456 | up_read(&lov->lov_notify_lock); | |
457 | CERROR("unexpected notification of %s %s!\n", | |
458 | watched->obd_type->typ_name, | |
459 | watched->obd_name); | |
0a3bdb00 | 460 | return -EINVAL; |
d7e09d03 PT |
461 | } |
462 | uuid = &watched->u.cli.cl_target_uuid; | |
463 | ||
464 | /* Set OSC as active before notifying the observer, so the | |
465 | * observer can use the OSC normally. | |
466 | */ | |
467 | rc = lov_set_osc_active(obd, uuid, ev); | |
468 | if (rc < 0) { | |
469 | up_read(&lov->lov_notify_lock); | |
470 | CERROR("event(%d) of %s failed: %d\n", ev, | |
471 | obd_uuid2str(uuid), rc); | |
0a3bdb00 | 472 | return rc; |
d7e09d03 PT |
473 | } |
474 | /* active event should be pass lov target index as data */ | |
475 | data = &rc; | |
476 | } | |
477 | ||
478 | /* Pass the notification up the chain. */ | |
479 | if (watched) { | |
480 | rc = obd_notify_observer(obd, watched, ev, data); | |
481 | } else { | |
482 | /* NULL watched means all osc's in the lov (only for syncs) */ | |
483 | /* sync event should be send lov idx as data */ | |
484 | struct lov_obd *lov = &obd->u.lov; | |
485 | int i, is_sync; | |
486 | ||
487 | data = &i; | |
488 | is_sync = (ev == OBD_NOTIFY_SYNC) || | |
489 | (ev == OBD_NOTIFY_SYNC_NONBLOCK); | |
490 | ||
491 | obd_getref(obd); | |
492 | for (i = 0; i < lov->desc.ld_tgt_count; i++) { | |
493 | if (!lov->lov_tgts[i]) | |
494 | continue; | |
495 | ||
496 | /* don't send sync event if target not | |
497 | * connected/activated */ | |
498 | if (is_sync && !lov->lov_tgts[i]->ltd_active) | |
499 | continue; | |
500 | ||
501 | rc = obd_notify_observer(obd, lov->lov_tgts[i]->ltd_obd, | |
502 | ev, data); | |
503 | if (rc) { | |
504 | CERROR("%s: notify %s of %s failed %d\n", | |
505 | obd->obd_name, | |
506 | obd->obd_observer->obd_name, | |
507 | lov->lov_tgts[i]->ltd_obd->obd_name, | |
508 | rc); | |
509 | } | |
510 | } | |
511 | obd_putref(obd); | |
512 | } | |
513 | ||
514 | up_read(&lov->lov_notify_lock); | |
0a3bdb00 | 515 | return rc; |
d7e09d03 PT |
516 | } |
517 | ||
518 | static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp, | |
519 | __u32 index, int gen, int active) | |
520 | { | |
521 | struct lov_obd *lov = &obd->u.lov; | |
522 | struct lov_tgt_desc *tgt; | |
523 | struct obd_device *tgt_obd; | |
524 | int rc; | |
d7e09d03 PT |
525 | |
526 | CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n", | |
527 | uuidp->uuid, index, gen, active); | |
528 | ||
529 | if (gen <= 0) { | |
530 | CERROR("request to add OBD %s with invalid generation: %d\n", | |
531 | uuidp->uuid, gen); | |
0a3bdb00 | 532 | return -EINVAL; |
d7e09d03 PT |
533 | } |
534 | ||
535 | tgt_obd = class_find_client_obd(uuidp, LUSTRE_OSC_NAME, | |
536 | &obd->obd_uuid); | |
537 | if (tgt_obd == NULL) | |
0a3bdb00 | 538 | return -EINVAL; |
d7e09d03 PT |
539 | |
540 | mutex_lock(&lov->lov_lock); | |
541 | ||
542 | if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) { | |
543 | tgt = lov->lov_tgts[index]; | |
544 | CERROR("UUID %s already assigned at LOV target index %d\n", | |
545 | obd_uuid2str(&tgt->ltd_uuid), index); | |
546 | mutex_unlock(&lov->lov_lock); | |
0a3bdb00 | 547 | return -EEXIST; |
d7e09d03 PT |
548 | } |
549 | ||
550 | if (index >= lov->lov_tgt_size) { | |
551 | /* We need to reallocate the lov target array. */ | |
552 | struct lov_tgt_desc **newtgts, **old = NULL; | |
553 | __u32 newsize, oldsize = 0; | |
554 | ||
2c0514ee | 555 | newsize = max_t(__u32, lov->lov_tgt_size, 2); |
d7e09d03 PT |
556 | while (newsize < index + 1) |
557 | newsize = newsize << 1; | |
558 | OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize); | |
559 | if (newtgts == NULL) { | |
560 | mutex_unlock(&lov->lov_lock); | |
0a3bdb00 | 561 | return -ENOMEM; |
d7e09d03 PT |
562 | } |
563 | ||
564 | if (lov->lov_tgt_size) { | |
565 | memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) * | |
566 | lov->lov_tgt_size); | |
567 | old = lov->lov_tgts; | |
568 | oldsize = lov->lov_tgt_size; | |
569 | } | |
570 | ||
571 | lov->lov_tgts = newtgts; | |
572 | lov->lov_tgt_size = newsize; | |
573 | smp_rmb(); | |
574 | if (old) | |
575 | OBD_FREE(old, sizeof(*old) * oldsize); | |
576 | ||
577 | CDEBUG(D_CONFIG, "tgts: %p size: %d\n", | |
578 | lov->lov_tgts, lov->lov_tgt_size); | |
579 | } | |
580 | ||
581 | OBD_ALLOC_PTR(tgt); | |
582 | if (!tgt) { | |
583 | mutex_unlock(&lov->lov_lock); | |
0a3bdb00 | 584 | return -ENOMEM; |
d7e09d03 PT |
585 | } |
586 | ||
587 | rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size); | |
588 | if (rc) { | |
589 | mutex_unlock(&lov->lov_lock); | |
590 | OBD_FREE_PTR(tgt); | |
0a3bdb00 | 591 | return rc; |
d7e09d03 PT |
592 | } |
593 | ||
594 | tgt->ltd_uuid = *uuidp; | |
595 | tgt->ltd_obd = tgt_obd; | |
596 | /* XXX - add a sanity check on the generation number. */ | |
597 | tgt->ltd_gen = gen; | |
598 | tgt->ltd_index = index; | |
599 | tgt->ltd_activate = active; | |
600 | lov->lov_tgts[index] = tgt; | |
601 | if (index >= lov->desc.ld_tgt_count) | |
602 | lov->desc.ld_tgt_count = index + 1; | |
603 | ||
604 | mutex_unlock(&lov->lov_lock); | |
605 | ||
606 | CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n", | |
607 | index, tgt->ltd_gen, lov->desc.ld_tgt_count); | |
608 | ||
609 | rc = obd_notify(obd, tgt_obd, OBD_NOTIFY_CREATE, &index); | |
610 | ||
611 | if (lov->lov_connects == 0) { | |
612 | /* lov_connect hasn't been called yet. We'll do the | |
613 | lov_connect_obd on this target when that fn first runs, | |
614 | because we don't know the connect flags yet. */ | |
0a3bdb00 | 615 | return 0; |
d7e09d03 PT |
616 | } |
617 | ||
618 | obd_getref(obd); | |
619 | ||
620 | rc = lov_connect_obd(obd, index, active, &lov->lov_ocd); | |
621 | if (rc) | |
18751668 | 622 | goto out; |
d7e09d03 PT |
623 | |
624 | /* connect to administrative disabled ost */ | |
18751668 JL |
625 | if (!tgt->ltd_exp) { |
626 | rc = 0; | |
627 | goto out; | |
628 | } | |
d7e09d03 PT |
629 | |
630 | if (lov->lov_cache != NULL) { | |
631 | rc = obd_set_info_async(NULL, tgt->ltd_exp, | |
632 | sizeof(KEY_CACHE_SET), KEY_CACHE_SET, | |
633 | sizeof(struct cl_client_cache), lov->lov_cache, | |
634 | NULL); | |
635 | if (rc < 0) | |
18751668 | 636 | goto out; |
d7e09d03 PT |
637 | } |
638 | ||
639 | rc = lov_notify(obd, tgt->ltd_exp->exp_obd, | |
640 | active ? OBD_NOTIFY_CONNECT : OBD_NOTIFY_INACTIVE, | |
641 | (void *)&index); | |
642 | ||
643 | out: | |
644 | if (rc) { | |
645 | CERROR("add failed (%d), deleting %s\n", rc, | |
646 | obd_uuid2str(&tgt->ltd_uuid)); | |
2046a81d | 647 | lov_del_target(obd, index, NULL, 0); |
d7e09d03 PT |
648 | } |
649 | obd_putref(obd); | |
0a3bdb00 | 650 | return rc; |
d7e09d03 PT |
651 | } |
652 | ||
653 | /* Schedule a target for deletion */ | |
654 | int lov_del_target(struct obd_device *obd, __u32 index, | |
655 | struct obd_uuid *uuidp, int gen) | |
656 | { | |
657 | struct lov_obd *lov = &obd->u.lov; | |
658 | int count = lov->desc.ld_tgt_count; | |
659 | int rc = 0; | |
d7e09d03 PT |
660 | |
661 | if (index >= count) { | |
662 | CERROR("LOV target index %d >= number of LOV OBDs %d.\n", | |
663 | index, count); | |
0a3bdb00 | 664 | return -EINVAL; |
d7e09d03 PT |
665 | } |
666 | ||
667 | /* to make sure there's no ongoing lov_notify() now */ | |
668 | down_write(&lov->lov_notify_lock); | |
669 | obd_getref(obd); | |
670 | ||
671 | if (!lov->lov_tgts[index]) { | |
672 | CERROR("LOV target at index %d is not setup.\n", index); | |
18751668 JL |
673 | rc = -EINVAL; |
674 | goto out; | |
d7e09d03 PT |
675 | } |
676 | ||
677 | if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) { | |
678 | CERROR("LOV target UUID %s at index %d doesn't match %s.\n", | |
679 | lov_uuid2str(lov, index), index, | |
680 | obd_uuid2str(uuidp)); | |
18751668 JL |
681 | rc = -EINVAL; |
682 | goto out; | |
d7e09d03 PT |
683 | } |
684 | ||
685 | CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n", | |
686 | lov_uuid2str(lov, index), index, | |
687 | lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp, | |
688 | lov->lov_tgts[index]->ltd_active); | |
689 | ||
690 | lov->lov_tgts[index]->ltd_reap = 1; | |
691 | lov->lov_death_row++; | |
692 | /* we really delete it from obd_putref */ | |
693 | out: | |
694 | obd_putref(obd); | |
695 | up_write(&lov->lov_notify_lock); | |
696 | ||
0a3bdb00 | 697 | return rc; |
d7e09d03 PT |
698 | } |
699 | ||
700 | static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt) | |
701 | { | |
702 | struct obd_device *osc_obd; | |
703 | ||
704 | LASSERT(tgt); | |
705 | LASSERT(tgt->ltd_reap); | |
706 | ||
707 | osc_obd = class_exp2obd(tgt->ltd_exp); | |
708 | ||
709 | CDEBUG(D_CONFIG, "Removing tgt %s : %s\n", | |
710 | tgt->ltd_uuid.uuid, | |
711 | osc_obd ? osc_obd->obd_name : "<no obd>"); | |
712 | ||
713 | if (tgt->ltd_exp) | |
714 | lov_disconnect_obd(obd, tgt); | |
715 | ||
716 | OBD_FREE_PTR(tgt); | |
717 | ||
718 | /* Manual cleanup - no cleanup logs to clean up the osc's. We must | |
719 | do it ourselves. And we can't do it from lov_cleanup, | |
720 | because we just lost our only reference to it. */ | |
721 | if (osc_obd) | |
722 | class_manual_cleanup(osc_obd); | |
723 | } | |
724 | ||
725 | void lov_fix_desc_stripe_size(__u64 *val) | |
726 | { | |
50dc198a AD |
727 | if (*val < LOV_MIN_STRIPE_SIZE) { |
728 | if (*val != 0) | |
729 | LCONSOLE_INFO("Increasing default stripe size to " | |
730 | "minimum %u\n", | |
081b7265 JH |
731 | LOV_DESC_STRIPE_SIZE_DEFAULT); |
732 | *val = LOV_DESC_STRIPE_SIZE_DEFAULT; | |
d7e09d03 PT |
733 | } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) { |
734 | *val &= ~(LOV_MIN_STRIPE_SIZE - 1); | |
b0f5aad5 | 735 | LCONSOLE_WARN("Changing default stripe size to %llu (a multiple of %u)\n", |
d7e09d03 PT |
736 | *val, LOV_MIN_STRIPE_SIZE); |
737 | } | |
738 | } | |
739 | ||
740 | void lov_fix_desc_stripe_count(__u32 *val) | |
741 | { | |
742 | if (*val == 0) | |
743 | *val = 1; | |
744 | } | |
745 | ||
746 | void lov_fix_desc_pattern(__u32 *val) | |
747 | { | |
748 | /* from lov_setstripe */ | |
749 | if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) { | |
750 | LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val); | |
751 | *val = 0; | |
752 | } | |
753 | } | |
754 | ||
755 | void lov_fix_desc_qos_maxage(__u32 *val) | |
756 | { | |
d7e09d03 | 757 | if (*val == 0) |
081b7265 | 758 | *val = LOV_DESC_QOS_MAXAGE_DEFAULT; |
d7e09d03 PT |
759 | } |
760 | ||
761 | void lov_fix_desc(struct lov_desc *desc) | |
762 | { | |
763 | lov_fix_desc_stripe_size(&desc->ld_default_stripe_size); | |
764 | lov_fix_desc_stripe_count(&desc->ld_default_stripe_count); | |
765 | lov_fix_desc_pattern(&desc->ld_pattern); | |
766 | lov_fix_desc_qos_maxage(&desc->ld_qos_maxage); | |
767 | } | |
768 | ||
769 | int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg) | |
770 | { | |
2046a81d | 771 | struct lprocfs_static_vars lvars = { NULL }; |
d7e09d03 PT |
772 | struct lov_desc *desc; |
773 | struct lov_obd *lov = &obd->u.lov; | |
774 | int rc; | |
d7e09d03 PT |
775 | |
776 | if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { | |
777 | CERROR("LOV setup requires a descriptor\n"); | |
0a3bdb00 | 778 | return -EINVAL; |
d7e09d03 PT |
779 | } |
780 | ||
781 | desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1); | |
782 | ||
783 | if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) { | |
784 | CERROR("descriptor size wrong: %d > %d\n", | |
785 | (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1)); | |
0a3bdb00 | 786 | return -EINVAL; |
d7e09d03 PT |
787 | } |
788 | ||
789 | if (desc->ld_magic != LOV_DESC_MAGIC) { | |
790 | if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) { | |
791 | CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n", | |
792 | obd->obd_name, desc); | |
793 | lustre_swab_lov_desc(desc); | |
794 | } else { | |
795 | CERROR("%s: Bad lov desc magic: %#x\n", | |
796 | obd->obd_name, desc->ld_magic); | |
0a3bdb00 | 797 | return -EINVAL; |
d7e09d03 PT |
798 | } |
799 | } | |
800 | ||
801 | lov_fix_desc(desc); | |
802 | ||
803 | desc->ld_active_tgt_count = 0; | |
804 | lov->desc = *desc; | |
805 | lov->lov_tgt_size = 0; | |
806 | ||
807 | mutex_init(&lov->lov_lock); | |
808 | atomic_set(&lov->lov_refcount, 0); | |
809 | lov->lov_sp_me = LUSTRE_SP_CLI; | |
810 | ||
811 | init_rwsem(&lov->lov_notify_lock); | |
812 | ||
813 | lov->lov_pools_hash_body = cfs_hash_create("POOLS", HASH_POOLS_CUR_BITS, | |
814 | HASH_POOLS_MAX_BITS, | |
815 | HASH_POOLS_BKT_BITS, 0, | |
816 | CFS_HASH_MIN_THETA, | |
817 | CFS_HASH_MAX_THETA, | |
818 | &pool_hash_operations, | |
819 | CFS_HASH_DEFAULT); | |
820 | INIT_LIST_HEAD(&lov->lov_pool_list); | |
821 | lov->lov_pool_count = 0; | |
822 | rc = lov_ost_pool_init(&lov->lov_packed, 0); | |
823 | if (rc) | |
18751668 | 824 | goto out; |
d7e09d03 PT |
825 | |
826 | lprocfs_lov_init_vars(&lvars); | |
827 | lprocfs_obd_setup(obd, lvars.obd_vars); | |
f267cdb4 | 828 | #if defined (CONFIG_PROC_FS) |
d7e09d03 | 829 | { |
5907838a | 830 | int rc1; |
d7e09d03 | 831 | |
5907838a | 832 | rc1 = lprocfs_seq_create(obd->obd_proc_entry, "target_obd", |
d7e09d03 | 833 | 0444, &lov_proc_target_fops, obd); |
5907838a | 834 | if (rc1) |
d7e09d03 PT |
835 | CWARN("Error adding the target_obd file\n"); |
836 | } | |
837 | #endif | |
838 | lov->lov_pool_proc_entry = lprocfs_register("pools", | |
839 | obd->obd_proc_entry, | |
840 | NULL, NULL); | |
841 | ||
0a3bdb00 | 842 | return 0; |
d7e09d03 PT |
843 | |
844 | out: | |
845 | return rc; | |
846 | } | |
847 | ||
848 | static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage) | |
849 | { | |
d7e09d03 PT |
850 | struct lov_obd *lov = &obd->u.lov; |
851 | ||
d7e09d03 PT |
852 | switch (stage) { |
853 | case OBD_CLEANUP_EARLY: { | |
854 | int i; | |
855 | for (i = 0; i < lov->desc.ld_tgt_count; i++) { | |
856 | if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) | |
857 | continue; | |
858 | obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp), | |
859 | OBD_CLEANUP_EARLY); | |
860 | } | |
861 | break; | |
862 | } | |
a5d490c2 | 863 | default: |
d7e09d03 PT |
864 | break; |
865 | } | |
a5d490c2 | 866 | |
e588f1bf | 867 | return 0; |
d7e09d03 PT |
868 | } |
869 | ||
870 | static int lov_cleanup(struct obd_device *obd) | |
871 | { | |
872 | struct lov_obd *lov = &obd->u.lov; | |
873 | struct list_head *pos, *tmp; | |
874 | struct pool_desc *pool; | |
d7e09d03 PT |
875 | |
876 | list_for_each_safe(pos, tmp, &lov->lov_pool_list) { | |
877 | pool = list_entry(pos, struct pool_desc, pool_list); | |
878 | /* free pool structs */ | |
879 | CDEBUG(D_INFO, "delete pool %p\n", pool); | |
880 | /* In the function below, .hs_keycmp resolves to | |
881 | * pool_hashkey_keycmp() */ | |
882 | /* coverity[overrun-buffer-val] */ | |
883 | lov_pool_del(obd, pool->pool_name); | |
884 | } | |
885 | cfs_hash_putref(lov->lov_pools_hash_body); | |
886 | lov_ost_pool_free(&lov->lov_packed); | |
887 | ||
888 | lprocfs_obd_cleanup(obd); | |
889 | if (lov->lov_tgts) { | |
890 | int i; | |
891 | obd_getref(obd); | |
892 | for (i = 0; i < lov->desc.ld_tgt_count; i++) { | |
893 | if (!lov->lov_tgts[i]) | |
894 | continue; | |
895 | ||
896 | /* Inactive targets may never have connected */ | |
897 | if (lov->lov_tgts[i]->ltd_active || | |
898 | atomic_read(&lov->lov_refcount)) | |
899 | /* We should never get here - these | |
900 | should have been removed in the | |
901 | disconnect. */ | |
902 | CERROR("lov tgt %d not cleaned!" | |
903 | " deathrow=%d, lovrc=%d\n", | |
904 | i, lov->lov_death_row, | |
905 | atomic_read(&lov->lov_refcount)); | |
e6be8e63 | 906 | lov_del_target(obd, i, NULL, 0); |
d7e09d03 PT |
907 | } |
908 | obd_putref(obd); | |
909 | OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) * | |
910 | lov->lov_tgt_size); | |
911 | lov->lov_tgt_size = 0; | |
912 | } | |
0a3bdb00 | 913 | return 0; |
d7e09d03 PT |
914 | } |
915 | ||
916 | int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg, | |
917 | __u32 *indexp, int *genp) | |
918 | { | |
919 | struct obd_uuid obd_uuid; | |
920 | int cmd; | |
921 | int rc = 0; | |
d7e09d03 | 922 | |
5f3a68f9 | 923 | switch (cmd = lcfg->lcfg_command) { |
d7e09d03 PT |
924 | case LCFG_LOV_ADD_OBD: |
925 | case LCFG_LOV_ADD_INA: | |
926 | case LCFG_LOV_DEL_OBD: { | |
927 | __u32 index; | |
928 | int gen; | |
929 | /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */ | |
18751668 JL |
930 | if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid)) { |
931 | rc = -EINVAL; | |
932 | goto out; | |
933 | } | |
d7e09d03 PT |
934 | |
935 | obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1)); | |
936 | ||
18751668 JL |
937 | if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", indexp) != 1) { |
938 | rc = -EINVAL; | |
939 | goto out; | |
940 | } | |
941 | if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", genp) != 1) { | |
942 | rc = -EINVAL; | |
943 | goto out; | |
944 | } | |
d7e09d03 PT |
945 | index = *indexp; |
946 | gen = *genp; | |
947 | if (cmd == LCFG_LOV_ADD_OBD) | |
948 | rc = lov_add_target(obd, &obd_uuid, index, gen, 1); | |
949 | else if (cmd == LCFG_LOV_ADD_INA) | |
950 | rc = lov_add_target(obd, &obd_uuid, index, gen, 0); | |
951 | else | |
952 | rc = lov_del_target(obd, index, &obd_uuid, gen); | |
18751668 | 953 | goto out; |
d7e09d03 PT |
954 | } |
955 | case LCFG_PARAM: { | |
e6be8e63 | 956 | struct lprocfs_static_vars lvars = { NULL }; |
d7e09d03 PT |
957 | struct lov_desc *desc = &(obd->u.lov.desc); |
958 | ||
18751668 JL |
959 | if (!desc) { |
960 | rc = -EINVAL; | |
961 | goto out; | |
962 | } | |
d7e09d03 PT |
963 | |
964 | lprocfs_lov_init_vars(&lvars); | |
965 | ||
966 | rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars, | |
967 | lcfg, obd); | |
968 | if (rc > 0) | |
969 | rc = 0; | |
18751668 | 970 | goto out; |
d7e09d03 PT |
971 | } |
972 | case LCFG_POOL_NEW: | |
973 | case LCFG_POOL_ADD: | |
974 | case LCFG_POOL_DEL: | |
975 | case LCFG_POOL_REM: | |
18751668 | 976 | goto out; |
d7e09d03 PT |
977 | |
978 | default: { | |
979 | CERROR("Unknown command: %d\n", lcfg->lcfg_command); | |
18751668 JL |
980 | rc = -EINVAL; |
981 | goto out; | |
d7e09d03 PT |
982 | |
983 | } | |
984 | } | |
985 | out: | |
0a3bdb00 | 986 | return rc; |
d7e09d03 PT |
987 | } |
988 | ||
989 | static int lov_recreate(struct obd_export *exp, struct obdo *src_oa, | |
990 | struct lov_stripe_md **ea, struct obd_trans_info *oti) | |
991 | { | |
992 | struct lov_stripe_md *obj_mdp, *lsm; | |
993 | struct lov_obd *lov = &exp->exp_obd->u.lov; | |
994 | unsigned ost_idx; | |
995 | int rc, i; | |
d7e09d03 PT |
996 | |
997 | LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS && | |
998 | src_oa->o_flags & OBD_FL_RECREATE_OBJS); | |
999 | ||
1000 | OBD_ALLOC(obj_mdp, sizeof(*obj_mdp)); | |
1001 | if (obj_mdp == NULL) | |
0a3bdb00 | 1002 | return -ENOMEM; |
d7e09d03 PT |
1003 | |
1004 | ost_idx = src_oa->o_nlink; | |
1005 | lsm = *ea; | |
18751668 JL |
1006 | if (lsm == NULL) { |
1007 | rc = -EINVAL; | |
1008 | goto out; | |
1009 | } | |
d7e09d03 | 1010 | if (ost_idx >= lov->desc.ld_tgt_count || |
18751668 JL |
1011 | !lov->lov_tgts[ost_idx]) { |
1012 | rc = -EINVAL; | |
1013 | goto out; | |
1014 | } | |
d7e09d03 PT |
1015 | |
1016 | for (i = 0; i < lsm->lsm_stripe_count; i++) { | |
1017 | if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) { | |
1018 | if (ostid_id(&lsm->lsm_oinfo[i]->loi_oi) != | |
18751668 JL |
1019 | ostid_id(&src_oa->o_oi)) { |
1020 | rc = -EINVAL; | |
1021 | goto out; | |
1022 | } | |
d7e09d03 PT |
1023 | break; |
1024 | } | |
1025 | } | |
18751668 JL |
1026 | if (i == lsm->lsm_stripe_count) { |
1027 | rc = -EINVAL; | |
1028 | goto out; | |
1029 | } | |
d7e09d03 PT |
1030 | |
1031 | rc = obd_create(NULL, lov->lov_tgts[ost_idx]->ltd_exp, | |
1032 | src_oa, &obj_mdp, oti); | |
1033 | out: | |
1034 | OBD_FREE(obj_mdp, sizeof(*obj_mdp)); | |
0a3bdb00 | 1035 | return rc; |
d7e09d03 PT |
1036 | } |
1037 | ||
1038 | /* the LOV expects oa->o_id to be set to the LOV object id */ | |
1039 | static int lov_create(const struct lu_env *env, struct obd_export *exp, | |
1040 | struct obdo *src_oa, struct lov_stripe_md **ea, | |
1041 | struct obd_trans_info *oti) | |
1042 | { | |
1043 | struct lov_obd *lov; | |
1044 | int rc = 0; | |
d7e09d03 PT |
1045 | |
1046 | LASSERT(ea != NULL); | |
1047 | if (exp == NULL) | |
0a3bdb00 | 1048 | return -EINVAL; |
d7e09d03 PT |
1049 | |
1050 | if ((src_oa->o_valid & OBD_MD_FLFLAGS) && | |
1051 | src_oa->o_flags == OBD_FL_DELORPHAN) { | |
1052 | /* should be used with LOV anymore */ | |
1053 | LBUG(); | |
1054 | } | |
1055 | ||
1056 | lov = &exp->exp_obd->u.lov; | |
1057 | if (!lov->desc.ld_active_tgt_count) | |
0a3bdb00 | 1058 | return -EIO; |
d7e09d03 PT |
1059 | |
1060 | obd_getref(exp->exp_obd); | |
1061 | /* Recreate a specific object id at the given OST index */ | |
1062 | if ((src_oa->o_valid & OBD_MD_FLFLAGS) && | |
1063 | (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) { | |
1064 | rc = lov_recreate(exp, src_oa, ea, oti); | |
1065 | } | |
1066 | ||
1067 | obd_putref(exp->exp_obd); | |
0a3bdb00 | 1068 | return rc; |
d7e09d03 PT |
1069 | } |
1070 | ||
1071 | #define ASSERT_LSM_MAGIC(lsmp) \ | |
1072 | do { \ | |
1073 | LASSERT((lsmp) != NULL); \ | |
1074 | LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 || \ | |
1075 | (lsmp)->lsm_magic == LOV_MAGIC_V3), \ | |
1076 | "%p->lsm_magic=%x\n", (lsmp), (lsmp)->lsm_magic); \ | |
1077 | } while (0) | |
1078 | ||
1079 | static int lov_destroy(const struct lu_env *env, struct obd_export *exp, | |
1080 | struct obdo *oa, struct lov_stripe_md *lsm, | |
1081 | struct obd_trans_info *oti, struct obd_export *md_exp, | |
1082 | void *capa) | |
1083 | { | |
1084 | struct lov_request_set *set; | |
1085 | struct obd_info oinfo; | |
1086 | struct lov_request *req; | |
1087 | struct list_head *pos; | |
1088 | struct lov_obd *lov; | |
1089 | int rc = 0, err = 0; | |
d7e09d03 PT |
1090 | |
1091 | ASSERT_LSM_MAGIC(lsm); | |
1092 | ||
1093 | if (!exp || !exp->exp_obd) | |
0a3bdb00 | 1094 | return -ENODEV; |
d7e09d03 PT |
1095 | |
1096 | if (oa->o_valid & OBD_MD_FLCOOKIE) { | |
1097 | LASSERT(oti); | |
1098 | LASSERT(oti->oti_logcookies); | |
1099 | } | |
1100 | ||
1101 | lov = &exp->exp_obd->u.lov; | |
1102 | obd_getref(exp->exp_obd); | |
1103 | rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set); | |
1104 | if (rc) | |
18751668 | 1105 | goto out; |
d7e09d03 | 1106 | |
66e7a94a | 1107 | list_for_each(pos, &set->set_list) { |
d7e09d03 PT |
1108 | req = list_entry(pos, struct lov_request, rq_link); |
1109 | ||
1110 | if (oa->o_valid & OBD_MD_FLCOOKIE) | |
1111 | oti->oti_logcookies = set->set_cookies + req->rq_stripe; | |
1112 | ||
1113 | err = obd_destroy(env, lov->lov_tgts[req->rq_idx]->ltd_exp, | |
1114 | req->rq_oi.oi_oa, NULL, oti, NULL, capa); | |
1115 | err = lov_update_common_set(set, req, err); | |
1116 | if (err) { | |
1117 | CERROR("%s: destroying objid "DOSTID" subobj " | |
1118 | DOSTID" on OST idx %d: rc = %d\n", | |
1119 | exp->exp_obd->obd_name, POSTID(&oa->o_oi), | |
1120 | POSTID(&req->rq_oi.oi_oa->o_oi), | |
1121 | req->rq_idx, err); | |
1122 | if (!rc) | |
1123 | rc = err; | |
1124 | } | |
1125 | } | |
1126 | ||
1127 | if (rc == 0) { | |
1128 | LASSERT(lsm_op_find(lsm->lsm_magic) != NULL); | |
1129 | rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp); | |
1130 | } | |
1131 | err = lov_fini_destroy_set(set); | |
1132 | out: | |
1133 | obd_putref(exp->exp_obd); | |
0a3bdb00 | 1134 | return rc ? rc : err; |
d7e09d03 PT |
1135 | } |
1136 | ||
d7e09d03 PT |
1137 | static int lov_getattr_interpret(struct ptlrpc_request_set *rqset, |
1138 | void *data, int rc) | |
1139 | { | |
1140 | struct lov_request_set *lovset = (struct lov_request_set *)data; | |
1141 | int err; | |
d7e09d03 | 1142 | |
1208bcd8 | 1143 | /* don't do attribute merge if this async op failed */ |
d7e09d03 PT |
1144 | if (rc) |
1145 | atomic_set(&lovset->set_completes, 0); | |
1146 | err = lov_fini_getattr_set(lovset); | |
0a3bdb00 | 1147 | return rc ? rc : err; |
d7e09d03 PT |
1148 | } |
1149 | ||
1150 | static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo, | |
1151 | struct ptlrpc_request_set *rqset) | |
1152 | { | |
1153 | struct lov_request_set *lovset; | |
1154 | struct lov_obd *lov; | |
1155 | struct list_head *pos; | |
1156 | struct lov_request *req; | |
1157 | int rc = 0, err; | |
d7e09d03 PT |
1158 | |
1159 | LASSERT(oinfo); | |
1160 | ASSERT_LSM_MAGIC(oinfo->oi_md); | |
1161 | ||
1162 | if (!exp || !exp->exp_obd) | |
0a3bdb00 | 1163 | return -ENODEV; |
d7e09d03 PT |
1164 | |
1165 | lov = &exp->exp_obd->u.lov; | |
1166 | ||
1167 | rc = lov_prep_getattr_set(exp, oinfo, &lovset); | |
1168 | if (rc) | |
0a3bdb00 | 1169 | return rc; |
d7e09d03 PT |
1170 | |
1171 | CDEBUG(D_INFO, "objid "DOSTID": %ux%u byte stripes\n", | |
1172 | POSTID(&oinfo->oi_md->lsm_oi), oinfo->oi_md->lsm_stripe_count, | |
1173 | oinfo->oi_md->lsm_stripe_size); | |
1174 | ||
1175 | list_for_each(pos, &lovset->set_list) { | |
1176 | req = list_entry(pos, struct lov_request, rq_link); | |
1177 | ||
1178 | CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx" | |
1179 | "%u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe, | |
1180 | POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx); | |
1181 | rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp, | |
1182 | &req->rq_oi, rqset); | |
1183 | if (rc) { | |
1184 | CERROR("%s: getattr objid "DOSTID" subobj" | |
1185 | DOSTID" on OST idx %d: rc = %d\n", | |
1186 | exp->exp_obd->obd_name, | |
1187 | POSTID(&oinfo->oi_oa->o_oi), | |
1188 | POSTID(&req->rq_oi.oi_oa->o_oi), | |
1189 | req->rq_idx, rc); | |
18751668 | 1190 | goto out; |
d7e09d03 PT |
1191 | } |
1192 | } | |
1193 | ||
1194 | if (!list_empty(&rqset->set_requests)) { | |
1195 | LASSERT(rc == 0); | |
66e7a94a | 1196 | LASSERT(rqset->set_interpret == NULL); |
d7e09d03 PT |
1197 | rqset->set_interpret = lov_getattr_interpret; |
1198 | rqset->set_arg = (void *)lovset; | |
0a3bdb00 | 1199 | return rc; |
d7e09d03 PT |
1200 | } |
1201 | out: | |
1202 | if (rc) | |
1203 | atomic_set(&lovset->set_completes, 0); | |
1204 | err = lov_fini_getattr_set(lovset); | |
0a3bdb00 | 1205 | return rc ? rc : err; |
d7e09d03 PT |
1206 | } |
1207 | ||
d7e09d03 PT |
1208 | static int lov_setattr_interpret(struct ptlrpc_request_set *rqset, |
1209 | void *data, int rc) | |
1210 | { | |
1211 | struct lov_request_set *lovset = (struct lov_request_set *)data; | |
1212 | int err; | |
d7e09d03 PT |
1213 | |
1214 | if (rc) | |
1215 | atomic_set(&lovset->set_completes, 0); | |
1216 | err = lov_fini_setattr_set(lovset); | |
0a3bdb00 | 1217 | return rc ? rc : err; |
d7e09d03 PT |
1218 | } |
1219 | ||
1220 | /* If @oti is given, the request goes from MDS and responses from OSTs are not | |
1221 | needed. Otherwise, a client is waiting for responses. */ | |
1222 | static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo, | |
1223 | struct obd_trans_info *oti, | |
1224 | struct ptlrpc_request_set *rqset) | |
1225 | { | |
1226 | struct lov_request_set *set; | |
1227 | struct lov_request *req; | |
1228 | struct list_head *pos; | |
1229 | struct lov_obd *lov; | |
1230 | int rc = 0; | |
d7e09d03 PT |
1231 | |
1232 | LASSERT(oinfo); | |
1233 | ASSERT_LSM_MAGIC(oinfo->oi_md); | |
1234 | if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) { | |
1235 | LASSERT(oti); | |
1236 | LASSERT(oti->oti_logcookies); | |
1237 | } | |
1238 | ||
1239 | if (!exp || !exp->exp_obd) | |
0a3bdb00 | 1240 | return -ENODEV; |
d7e09d03 PT |
1241 | |
1242 | lov = &exp->exp_obd->u.lov; | |
1243 | rc = lov_prep_setattr_set(exp, oinfo, oti, &set); | |
1244 | if (rc) | |
0a3bdb00 | 1245 | return rc; |
d7e09d03 PT |
1246 | |
1247 | CDEBUG(D_INFO, "objid "DOSTID": %ux%u byte stripes\n", | |
1248 | POSTID(&oinfo->oi_md->lsm_oi), | |
1249 | oinfo->oi_md->lsm_stripe_count, | |
1250 | oinfo->oi_md->lsm_stripe_size); | |
1251 | ||
1252 | list_for_each(pos, &set->set_list) { | |
1253 | req = list_entry(pos, struct lov_request, rq_link); | |
1254 | ||
1255 | if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) | |
1256 | oti->oti_logcookies = set->set_cookies + req->rq_stripe; | |
1257 | ||
1258 | CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx" | |
1259 | "%u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe, | |
1260 | POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx); | |
1261 | ||
1262 | rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp, | |
1263 | &req->rq_oi, oti, rqset); | |
1264 | if (rc) { | |
1265 | CERROR("error: setattr objid "DOSTID" subobj" | |
1266 | DOSTID" on OST idx %d: rc = %d\n", | |
1267 | POSTID(&set->set_oi->oi_oa->o_oi), | |
1268 | POSTID(&req->rq_oi.oi_oa->o_oi), | |
1269 | req->rq_idx, rc); | |
1270 | break; | |
1271 | } | |
1272 | } | |
1273 | ||
1274 | /* If we are not waiting for responses on async requests, return. */ | |
1275 | if (rc || !rqset || list_empty(&rqset->set_requests)) { | |
1276 | int err; | |
1277 | if (rc) | |
1278 | atomic_set(&set->set_completes, 0); | |
1279 | err = lov_fini_setattr_set(set); | |
0a3bdb00 | 1280 | return rc ? rc : err; |
d7e09d03 PT |
1281 | } |
1282 | ||
1283 | LASSERT(rqset->set_interpret == NULL); | |
1284 | rqset->set_interpret = lov_setattr_interpret; | |
1285 | rqset->set_arg = (void *)set; | |
1286 | ||
0a3bdb00 | 1287 | return 0; |
d7e09d03 PT |
1288 | } |
1289 | ||
d7e09d03 PT |
1290 | /* find any ldlm lock of the inode in lov |
1291 | * return 0 not find | |
1292 | * 1 find one | |
1293 | * < 0 error */ | |
1294 | static int lov_find_cbdata(struct obd_export *exp, | |
1295 | struct lov_stripe_md *lsm, ldlm_iterator_t it, | |
1296 | void *data) | |
1297 | { | |
1298 | struct lov_obd *lov; | |
1299 | int rc = 0, i; | |
d7e09d03 PT |
1300 | |
1301 | ASSERT_LSM_MAGIC(lsm); | |
1302 | ||
1303 | if (!exp || !exp->exp_obd) | |
0a3bdb00 | 1304 | return -ENODEV; |
d7e09d03 PT |
1305 | |
1306 | lov = &exp->exp_obd->u.lov; | |
1307 | for (i = 0; i < lsm->lsm_stripe_count; i++) { | |
1308 | struct lov_stripe_md submd; | |
1309 | struct lov_oinfo *loi = lsm->lsm_oinfo[i]; | |
1310 | ||
1311 | if (!lov->lov_tgts[loi->loi_ost_idx]) { | |
1312 | CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx); | |
1313 | continue; | |
1314 | } | |
1315 | submd.lsm_oi = loi->loi_oi; | |
1316 | submd.lsm_stripe_count = 0; | |
1317 | rc = obd_find_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, | |
1318 | &submd, it, data); | |
1319 | if (rc != 0) | |
0a3bdb00 | 1320 | return rc; |
d7e09d03 | 1321 | } |
0a3bdb00 | 1322 | return rc; |
d7e09d03 PT |
1323 | } |
1324 | ||
d7e09d03 PT |
1325 | int lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc) |
1326 | { | |
1327 | struct lov_request_set *lovset = (struct lov_request_set *)data; | |
1328 | int err; | |
d7e09d03 PT |
1329 | |
1330 | if (rc) | |
1331 | atomic_set(&lovset->set_completes, 0); | |
1332 | ||
1333 | err = lov_fini_statfs_set(lovset); | |
0a3bdb00 | 1334 | return rc ? rc : err; |
d7e09d03 PT |
1335 | } |
1336 | ||
1337 | static int lov_statfs_async(struct obd_export *exp, struct obd_info *oinfo, | |
1338 | __u64 max_age, struct ptlrpc_request_set *rqset) | |
1339 | { | |
1340 | struct obd_device *obd = class_exp2obd(exp); | |
1341 | struct lov_request_set *set; | |
1342 | struct lov_request *req; | |
1343 | struct list_head *pos; | |
1344 | struct lov_obd *lov; | |
1345 | int rc = 0; | |
d7e09d03 PT |
1346 | |
1347 | LASSERT(oinfo != NULL); | |
1348 | LASSERT(oinfo->oi_osfs != NULL); | |
1349 | ||
1350 | lov = &obd->u.lov; | |
1351 | rc = lov_prep_statfs_set(obd, oinfo, &set); | |
1352 | if (rc) | |
0a3bdb00 | 1353 | return rc; |
d7e09d03 | 1354 | |
66e7a94a | 1355 | list_for_each(pos, &set->set_list) { |
d7e09d03 PT |
1356 | req = list_entry(pos, struct lov_request, rq_link); |
1357 | rc = obd_statfs_async(lov->lov_tgts[req->rq_idx]->ltd_exp, | |
1358 | &req->rq_oi, max_age, rqset); | |
1359 | if (rc) | |
1360 | break; | |
1361 | } | |
1362 | ||
1363 | if (rc || list_empty(&rqset->set_requests)) { | |
1364 | int err; | |
1365 | if (rc) | |
1366 | atomic_set(&set->set_completes, 0); | |
1367 | err = lov_fini_statfs_set(set); | |
0a3bdb00 | 1368 | return rc ? rc : err; |
d7e09d03 PT |
1369 | } |
1370 | ||
1371 | LASSERT(rqset->set_interpret == NULL); | |
1372 | rqset->set_interpret = lov_statfs_interpret; | |
1373 | rqset->set_arg = (void *)set; | |
0a3bdb00 | 1374 | return 0; |
d7e09d03 PT |
1375 | } |
1376 | ||
1377 | static int lov_statfs(const struct lu_env *env, struct obd_export *exp, | |
1378 | struct obd_statfs *osfs, __u64 max_age, __u32 flags) | |
1379 | { | |
1380 | struct ptlrpc_request_set *set = NULL; | |
1381 | struct obd_info oinfo = { { { 0 } } }; | |
1382 | int rc = 0; | |
d7e09d03 PT |
1383 | |
1384 | /* for obdclass we forbid using obd_statfs_rqset, but prefer using async | |
1385 | * statfs requests */ | |
1386 | set = ptlrpc_prep_set(); | |
1387 | if (set == NULL) | |
0a3bdb00 | 1388 | return -ENOMEM; |
d7e09d03 PT |
1389 | |
1390 | oinfo.oi_osfs = osfs; | |
1391 | oinfo.oi_flags = flags; | |
1392 | rc = lov_statfs_async(exp, &oinfo, max_age, set); | |
1393 | if (rc == 0) | |
1394 | rc = ptlrpc_set_wait(set); | |
1395 | ptlrpc_set_destroy(set); | |
1396 | ||
0a3bdb00 | 1397 | return rc; |
d7e09d03 PT |
1398 | } |
1399 | ||
1400 | static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len, | |
1401 | void *karg, void *uarg) | |
1402 | { | |
1403 | struct obd_device *obddev = class_exp2obd(exp); | |
1404 | struct lov_obd *lov = &obddev->u.lov; | |
1405 | int i = 0, rc = 0, count = lov->desc.ld_tgt_count; | |
1406 | struct obd_uuid *uuidp; | |
d7e09d03 PT |
1407 | |
1408 | switch (cmd) { | |
1409 | case IOC_OBD_STATFS: { | |
1410 | struct obd_ioctl_data *data = karg; | |
1411 | struct obd_device *osc_obd; | |
1412 | struct obd_statfs stat_buf = {0}; | |
1413 | __u32 index; | |
1414 | __u32 flags; | |
1415 | ||
1416 | memcpy(&index, data->ioc_inlbuf2, sizeof(__u32)); | |
1417 | if ((index >= count)) | |
0a3bdb00 | 1418 | return -ENODEV; |
d7e09d03 PT |
1419 | |
1420 | if (!lov->lov_tgts[index]) | |
1421 | /* Try again with the next index */ | |
0a3bdb00 | 1422 | return -EAGAIN; |
d7e09d03 | 1423 | if (!lov->lov_tgts[index]->ltd_active) |
0a3bdb00 | 1424 | return -ENODATA; |
d7e09d03 PT |
1425 | |
1426 | osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp); | |
1427 | if (!osc_obd) | |
0a3bdb00 | 1428 | return -EINVAL; |
d7e09d03 PT |
1429 | |
1430 | /* copy UUID */ | |
1431 | if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd), | |
1432 | min((int) data->ioc_plen2, | |
1433 | (int) sizeof(struct obd_uuid)))) | |
0a3bdb00 | 1434 | return -EFAULT; |
d7e09d03 | 1435 | |
bcc3b704 | 1436 | flags = uarg ? *(__u32 *)uarg : 0; |
d7e09d03 PT |
1437 | /* got statfs data */ |
1438 | rc = obd_statfs(NULL, lov->lov_tgts[index]->ltd_exp, &stat_buf, | |
1439 | cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), | |
1440 | flags); | |
1441 | if (rc) | |
0a3bdb00 | 1442 | return rc; |
d7e09d03 PT |
1443 | if (copy_to_user(data->ioc_pbuf1, &stat_buf, |
1444 | min((int) data->ioc_plen1, | |
1445 | (int) sizeof(stat_buf)))) | |
0a3bdb00 | 1446 | return -EFAULT; |
d7e09d03 PT |
1447 | break; |
1448 | } | |
1449 | case OBD_IOC_LOV_GET_CONFIG: { | |
1450 | struct obd_ioctl_data *data; | |
1451 | struct lov_desc *desc; | |
1452 | char *buf = NULL; | |
1453 | __u32 *genp; | |
1454 | ||
1455 | len = 0; | |
1456 | if (obd_ioctl_getdata(&buf, &len, (void *)uarg)) | |
0a3bdb00 | 1457 | return -EINVAL; |
d7e09d03 PT |
1458 | |
1459 | data = (struct obd_ioctl_data *)buf; | |
1460 | ||
1461 | if (sizeof(*desc) > data->ioc_inllen1) { | |
1462 | obd_ioctl_freedata(buf, len); | |
0a3bdb00 | 1463 | return -EINVAL; |
d7e09d03 PT |
1464 | } |
1465 | ||
1466 | if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) { | |
1467 | obd_ioctl_freedata(buf, len); | |
0a3bdb00 | 1468 | return -EINVAL; |
d7e09d03 PT |
1469 | } |
1470 | ||
1471 | if (sizeof(__u32) * count > data->ioc_inllen3) { | |
1472 | obd_ioctl_freedata(buf, len); | |
0a3bdb00 | 1473 | return -EINVAL; |
d7e09d03 PT |
1474 | } |
1475 | ||
1476 | desc = (struct lov_desc *)data->ioc_inlbuf1; | |
1477 | memcpy(desc, &(lov->desc), sizeof(*desc)); | |
1478 | ||
1479 | uuidp = (struct obd_uuid *)data->ioc_inlbuf2; | |
1480 | genp = (__u32 *)data->ioc_inlbuf3; | |
1481 | /* the uuid will be empty for deleted OSTs */ | |
1482 | for (i = 0; i < count; i++, uuidp++, genp++) { | |
1483 | if (!lov->lov_tgts[i]) | |
1484 | continue; | |
1485 | *uuidp = lov->lov_tgts[i]->ltd_uuid; | |
1486 | *genp = lov->lov_tgts[i]->ltd_gen; | |
1487 | } | |
1488 | ||
1489 | if (copy_to_user((void *)uarg, buf, len)) | |
1490 | rc = -EFAULT; | |
1491 | obd_ioctl_freedata(buf, len); | |
1492 | break; | |
1493 | } | |
d7e09d03 PT |
1494 | case LL_IOC_LOV_GETSTRIPE: |
1495 | rc = lov_getstripe(exp, karg, uarg); | |
1496 | break; | |
d7e09d03 PT |
1497 | case OBD_IOC_QUOTACTL: { |
1498 | struct if_quotactl *qctl = karg; | |
1499 | struct lov_tgt_desc *tgt = NULL; | |
1500 | struct obd_quotactl *oqctl; | |
1501 | ||
1502 | if (qctl->qc_valid == QC_OSTIDX) { | |
1503 | if (qctl->qc_idx < 0 || count <= qctl->qc_idx) | |
0a3bdb00 | 1504 | return -EINVAL; |
d7e09d03 PT |
1505 | |
1506 | tgt = lov->lov_tgts[qctl->qc_idx]; | |
1507 | if (!tgt || !tgt->ltd_exp) | |
0a3bdb00 | 1508 | return -EINVAL; |
d7e09d03 PT |
1509 | } else if (qctl->qc_valid == QC_UUID) { |
1510 | for (i = 0; i < count; i++) { | |
1511 | tgt = lov->lov_tgts[i]; | |
1512 | if (!tgt || | |
1513 | !obd_uuid_equals(&tgt->ltd_uuid, | |
1514 | &qctl->obd_uuid)) | |
1515 | continue; | |
1516 | ||
1517 | if (tgt->ltd_exp == NULL) | |
0a3bdb00 | 1518 | return -EINVAL; |
d7e09d03 PT |
1519 | |
1520 | break; | |
1521 | } | |
1522 | } else { | |
0a3bdb00 | 1523 | return -EINVAL; |
d7e09d03 PT |
1524 | } |
1525 | ||
1526 | if (i >= count) | |
0a3bdb00 | 1527 | return -EAGAIN; |
d7e09d03 PT |
1528 | |
1529 | LASSERT(tgt && tgt->ltd_exp); | |
1530 | OBD_ALLOC_PTR(oqctl); | |
1531 | if (!oqctl) | |
0a3bdb00 | 1532 | return -ENOMEM; |
d7e09d03 PT |
1533 | |
1534 | QCTL_COPY(oqctl, qctl); | |
1535 | rc = obd_quotactl(tgt->ltd_exp, oqctl); | |
1536 | if (rc == 0) { | |
1537 | QCTL_COPY(qctl, oqctl); | |
1538 | qctl->qc_valid = QC_OSTIDX; | |
1539 | qctl->obd_uuid = tgt->ltd_uuid; | |
1540 | } | |
1541 | OBD_FREE_PTR(oqctl); | |
1542 | break; | |
1543 | } | |
1544 | default: { | |
1545 | int set = 0; | |
1546 | ||
1547 | if (count == 0) | |
0a3bdb00 | 1548 | return -ENOTTY; |
d7e09d03 PT |
1549 | |
1550 | for (i = 0; i < count; i++) { | |
1551 | int err; | |
1552 | struct obd_device *osc_obd; | |
1553 | ||
1554 | /* OST was disconnected */ | |
1555 | if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp) | |
1556 | continue; | |
1557 | ||
1558 | /* ll_umount_begin() sets force flag but for lov, not | |
1559 | * osc. Let's pass it through */ | |
1560 | osc_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp); | |
1561 | osc_obd->obd_force = obddev->obd_force; | |
1562 | err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp, | |
1563 | len, karg, uarg); | |
1564 | if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) { | |
0a3bdb00 | 1565 | return err; |
d7e09d03 PT |
1566 | } else if (err) { |
1567 | if (lov->lov_tgts[i]->ltd_active) { | |
1568 | CDEBUG(err == -ENOTTY ? | |
1569 | D_IOCTL : D_WARNING, | |
1570 | "iocontrol OSC %s on OST " | |
1571 | "idx %d cmd %x: err = %d\n", | |
1572 | lov_uuid2str(lov, i), | |
1573 | i, cmd, err); | |
1574 | if (!rc) | |
1575 | rc = err; | |
1576 | } | |
1577 | } else { | |
1578 | set = 1; | |
1579 | } | |
1580 | } | |
1581 | if (!set && !rc) | |
1582 | rc = -EIO; | |
1583 | } | |
1584 | } | |
1585 | ||
0a3bdb00 | 1586 | return rc; |
d7e09d03 PT |
1587 | } |
1588 | ||
1589 | #define FIEMAP_BUFFER_SIZE 4096 | |
1590 | ||
1591 | /** | |
1592 | * Non-zero fe_logical indicates that this is a continuation FIEMAP | |
1593 | * call. The local end offset and the device are sent in the first | |
1594 | * fm_extent. This function calculates the stripe number from the index. | |
1595 | * This function returns a stripe_no on which mapping is to be restarted. | |
1596 | * | |
1597 | * This function returns fm_end_offset which is the in-OST offset at which | |
1598 | * mapping should be restarted. If fm_end_offset=0 is returned then caller | |
1599 | * will re-calculate proper offset in next stripe. | |
1600 | * Note that the first extent is passed to lov_get_info via the value field. | |
1601 | * | |
1602 | * \param fiemap fiemap request header | |
1603 | * \param lsm striping information for the file | |
1604 | * \param fm_start logical start of mapping | |
1605 | * \param fm_end logical end of mapping | |
1606 | * \param start_stripe starting stripe will be returned in this | |
1607 | */ | |
21aef7d9 OD |
1608 | u64 fiemap_calc_fm_end_offset(struct ll_user_fiemap *fiemap, |
1609 | struct lov_stripe_md *lsm, u64 fm_start, | |
1610 | u64 fm_end, int *start_stripe) | |
d7e09d03 | 1611 | { |
21aef7d9 OD |
1612 | u64 local_end = fiemap->fm_extents[0].fe_logical; |
1613 | u64 lun_start, lun_end; | |
1614 | u64 fm_end_offset; | |
d7e09d03 PT |
1615 | int stripe_no = -1, i; |
1616 | ||
1617 | if (fiemap->fm_extent_count == 0 || | |
1618 | fiemap->fm_extents[0].fe_logical == 0) | |
1619 | return 0; | |
1620 | ||
1621 | /* Find out stripe_no from ost_index saved in the fe_device */ | |
1622 | for (i = 0; i < lsm->lsm_stripe_count; i++) { | |
1623 | if (lsm->lsm_oinfo[i]->loi_ost_idx == | |
1624 | fiemap->fm_extents[0].fe_device) { | |
1625 | stripe_no = i; | |
1626 | break; | |
1627 | } | |
1628 | } | |
1629 | if (stripe_no == -1) | |
1630 | return -EINVAL; | |
1631 | ||
1632 | /* If we have finished mapping on previous device, shift logical | |
1633 | * offset to start of next device */ | |
1634 | if ((lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end, | |
1635 | &lun_start, &lun_end)) != 0 && | |
1636 | local_end < lun_end) { | |
1637 | fm_end_offset = local_end; | |
1638 | *start_stripe = stripe_no; | |
1639 | } else { | |
1640 | /* This is a special value to indicate that caller should | |
1641 | * calculate offset in next stripe. */ | |
1642 | fm_end_offset = 0; | |
1643 | *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count; | |
1644 | } | |
1645 | ||
1646 | return fm_end_offset; | |
1647 | } | |
1648 | ||
1649 | /** | |
1650 | * We calculate on which OST the mapping will end. If the length of mapping | |
1651 | * is greater than (stripe_size * stripe_count) then the last_stripe will | |
1652 | * will be one just before start_stripe. Else we check if the mapping | |
1653 | * intersects each OST and find last_stripe. | |
1654 | * This function returns the last_stripe and also sets the stripe_count | |
1655 | * over which the mapping is spread | |
1656 | * | |
1657 | * \param lsm striping information for the file | |
1658 | * \param fm_start logical start of mapping | |
1659 | * \param fm_end logical end of mapping | |
1660 | * \param start_stripe starting stripe of the mapping | |
1661 | * \param stripe_count the number of stripes across which to map is returned | |
1662 | * | |
1663 | * \retval last_stripe return the last stripe of the mapping | |
1664 | */ | |
21aef7d9 OD |
1665 | int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, u64 fm_start, |
1666 | u64 fm_end, int start_stripe, | |
d7e09d03 PT |
1667 | int *stripe_count) |
1668 | { | |
1669 | int last_stripe; | |
21aef7d9 | 1670 | u64 obd_start, obd_end; |
d7e09d03 PT |
1671 | int i, j; |
1672 | ||
1673 | if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) { | |
1674 | last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 : | |
1675 | start_stripe - 1); | |
1676 | *stripe_count = lsm->lsm_stripe_count; | |
1677 | } else { | |
1678 | for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count; | |
1679 | i = (i + 1) % lsm->lsm_stripe_count, j++) { | |
1680 | if ((lov_stripe_intersects(lsm, i, fm_start, fm_end, | |
1681 | &obd_start, &obd_end)) == 0) | |
1682 | break; | |
1683 | } | |
1684 | *stripe_count = j; | |
1685 | last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count; | |
1686 | } | |
1687 | ||
1688 | return last_stripe; | |
1689 | } | |
1690 | ||
1691 | /** | |
1692 | * Set fe_device and copy extents from local buffer into main return buffer. | |
1693 | * | |
1694 | * \param fiemap fiemap request header | |
1695 | * \param lcl_fm_ext array of local fiemap extents to be copied | |
1696 | * \param ost_index OST index to be written into the fm_device field for each | |
1697 | extent | |
1698 | * \param ext_count number of extents to be copied | |
1699 | * \param current_extent where to start copying in main extent array | |
1700 | */ | |
1701 | void fiemap_prepare_and_copy_exts(struct ll_user_fiemap *fiemap, | |
1702 | struct ll_fiemap_extent *lcl_fm_ext, | |
1703 | int ost_index, unsigned int ext_count, | |
1704 | int current_extent) | |
1705 | { | |
1706 | char *to; | |
1707 | int ext; | |
1708 | ||
1709 | for (ext = 0; ext < ext_count; ext++) { | |
1710 | lcl_fm_ext[ext].fe_device = ost_index; | |
1711 | lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET; | |
1712 | } | |
1713 | ||
1714 | /* Copy fm_extent's from fm_local to return buffer */ | |
1715 | to = (char *)fiemap + fiemap_count_to_size(current_extent); | |
1716 | memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent)); | |
1717 | } | |
1718 | ||
1719 | /** | |
1720 | * Break down the FIEMAP request and send appropriate calls to individual OSTs. | |
1721 | * This also handles the restarting of FIEMAP calls in case mapping overflows | |
1722 | * the available number of extents in single call. | |
1723 | */ | |
1724 | static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key, | |
1725 | __u32 *vallen, void *val, struct lov_stripe_md *lsm) | |
1726 | { | |
1727 | struct ll_fiemap_info_key *fm_key = key; | |
1728 | struct ll_user_fiemap *fiemap = val; | |
1729 | struct ll_user_fiemap *fm_local = NULL; | |
1730 | struct ll_fiemap_extent *lcl_fm_ext; | |
1731 | int count_local; | |
1732 | unsigned int get_num_extents = 0; | |
1733 | int ost_index = 0, actual_start_stripe, start_stripe; | |
21aef7d9 OD |
1734 | u64 fm_start, fm_end, fm_length, fm_end_offset; |
1735 | u64 curr_loc; | |
d7e09d03 PT |
1736 | int current_extent = 0, rc = 0, i; |
1737 | int ost_eof = 0; /* EOF for object */ | |
1738 | int ost_done = 0; /* done with required mapping for this OST? */ | |
1739 | int last_stripe; | |
1740 | int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count; | |
1741 | unsigned int buffer_size = FIEMAP_BUFFER_SIZE; | |
1742 | ||
18751668 JL |
1743 | if (!lsm_has_objects(lsm)) { |
1744 | rc = 0; | |
1745 | goto out; | |
1746 | } | |
d7e09d03 PT |
1747 | |
1748 | if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size) | |
1749 | buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count); | |
1750 | ||
1751 | OBD_ALLOC_LARGE(fm_local, buffer_size); | |
18751668 JL |
1752 | if (fm_local == NULL) { |
1753 | rc = -ENOMEM; | |
1754 | goto out; | |
1755 | } | |
d7e09d03 PT |
1756 | lcl_fm_ext = &fm_local->fm_extents[0]; |
1757 | ||
1758 | count_local = fiemap_size_to_count(buffer_size); | |
1759 | ||
1760 | memcpy(fiemap, &fm_key->fiemap, sizeof(*fiemap)); | |
1761 | fm_start = fiemap->fm_start; | |
1762 | fm_length = fiemap->fm_length; | |
1763 | /* Calculate start stripe, last stripe and length of mapping */ | |
1764 | actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start); | |
1765 | fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size : | |
1766 | fm_start + fm_length - 1); | |
1767 | /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */ | |
1768 | if (fm_end > fm_key->oa.o_size) | |
1769 | fm_end = fm_key->oa.o_size; | |
1770 | ||
1771 | last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end, | |
1772 | actual_start_stripe, &stripe_count); | |
1773 | ||
1774 | fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, | |
1775 | fm_end, &start_stripe); | |
18751668 JL |
1776 | if (fm_end_offset == -EINVAL) { |
1777 | rc = -EINVAL; | |
1778 | goto out; | |
1779 | } | |
d7e09d03 | 1780 | |
ebdc4fc5 BJ |
1781 | if (fiemap_count_to_size(fiemap->fm_extent_count) > *vallen) |
1782 | fiemap->fm_extent_count = fiemap_size_to_count(*vallen); | |
d7e09d03 PT |
1783 | if (fiemap->fm_extent_count == 0) { |
1784 | get_num_extents = 1; | |
1785 | count_local = 0; | |
1786 | } | |
d7e09d03 PT |
1787 | /* Check each stripe */ |
1788 | for (cur_stripe = start_stripe, i = 0; i < stripe_count; | |
1789 | i++, cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) { | |
21aef7d9 OD |
1790 | u64 req_fm_len; /* Stores length of required mapping */ |
1791 | u64 len_mapped_single_call; | |
1792 | u64 lun_start, lun_end, obd_object_end; | |
d7e09d03 PT |
1793 | unsigned int ext_count; |
1794 | ||
1795 | cur_stripe_wrap = cur_stripe; | |
1796 | ||
1797 | /* Find out range of mapping on this stripe */ | |
1798 | if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end, | |
1799 | &lun_start, &obd_object_end)) == 0) | |
1800 | continue; | |
1801 | ||
1802 | /* If this is a continuation FIEMAP call and we are on | |
1803 | * starting stripe then lun_start needs to be set to | |
1804 | * fm_end_offset */ | |
1805 | if (fm_end_offset != 0 && cur_stripe == start_stripe) | |
1806 | lun_start = fm_end_offset; | |
1807 | ||
1808 | if (fm_length != ~0ULL) { | |
1809 | /* Handle fm_start + fm_length overflow */ | |
1810 | if (fm_start + fm_length < fm_start) | |
1811 | fm_length = ~0ULL - fm_start; | |
1812 | lun_end = lov_size_to_stripe(lsm, fm_start + fm_length, | |
1813 | cur_stripe); | |
1814 | } else { | |
1815 | lun_end = ~0ULL; | |
1816 | } | |
1817 | ||
1818 | if (lun_start == lun_end) | |
1819 | continue; | |
1820 | ||
1821 | req_fm_len = obd_object_end - lun_start; | |
1822 | fm_local->fm_length = 0; | |
1823 | len_mapped_single_call = 0; | |
1824 | ||
1825 | /* If the output buffer is very large and the objects have many | |
1826 | * extents we may need to loop on a single OST repeatedly */ | |
1827 | ost_eof = 0; | |
1828 | ost_done = 0; | |
1829 | do { | |
1830 | if (get_num_extents == 0) { | |
1831 | /* Don't get too many extents. */ | |
1832 | if (current_extent + count_local > | |
1833 | fiemap->fm_extent_count) | |
1834 | count_local = fiemap->fm_extent_count - | |
1835 | current_extent; | |
1836 | } | |
1837 | ||
1838 | lun_start += len_mapped_single_call; | |
1839 | fm_local->fm_length = req_fm_len - len_mapped_single_call; | |
1840 | req_fm_len = fm_local->fm_length; | |
1841 | fm_local->fm_extent_count = count_local; | |
1842 | fm_local->fm_mapped_extents = 0; | |
1843 | fm_local->fm_flags = fiemap->fm_flags; | |
1844 | ||
1845 | fm_key->oa.o_oi = lsm->lsm_oinfo[cur_stripe]->loi_oi; | |
1846 | ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx; | |
1847 | ||
18751668 JL |
1848 | if (ost_index < 0 || |
1849 | ost_index >= lov->desc.ld_tgt_count) { | |
1850 | rc = -EINVAL; | |
1851 | goto out; | |
1852 | } | |
d7e09d03 PT |
1853 | |
1854 | /* If OST is inactive, return extent with UNKNOWN flag */ | |
1855 | if (!lov->lov_tgts[ost_index]->ltd_active) { | |
1856 | fm_local->fm_flags |= FIEMAP_EXTENT_LAST; | |
1857 | fm_local->fm_mapped_extents = 1; | |
1858 | ||
1859 | lcl_fm_ext[0].fe_logical = lun_start; | |
1860 | lcl_fm_ext[0].fe_length = obd_object_end - | |
1861 | lun_start; | |
1862 | lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN; | |
1863 | ||
1864 | goto inactive_tgt; | |
1865 | } | |
1866 | ||
1867 | fm_local->fm_start = lun_start; | |
1868 | fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER; | |
1869 | memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local)); | |
1870 | *vallen=fiemap_count_to_size(fm_local->fm_extent_count); | |
1871 | rc = obd_get_info(NULL, | |
1872 | lov->lov_tgts[ost_index]->ltd_exp, | |
1873 | keylen, key, vallen, fm_local, lsm); | |
1874 | if (rc != 0) | |
18751668 | 1875 | goto out; |
d7e09d03 PT |
1876 | |
1877 | inactive_tgt: | |
1878 | ext_count = fm_local->fm_mapped_extents; | |
1879 | if (ext_count == 0) { | |
1880 | ost_done = 1; | |
1881 | /* If last stripe has hole at the end, | |
1882 | * then we need to return */ | |
1883 | if (cur_stripe_wrap == last_stripe) { | |
1884 | fiemap->fm_mapped_extents = 0; | |
1885 | goto finish; | |
1886 | } | |
1887 | break; | |
1888 | } | |
1889 | ||
1890 | /* If we just need num of extents then go to next device */ | |
1891 | if (get_num_extents) { | |
1892 | current_extent += ext_count; | |
1893 | break; | |
1894 | } | |
1895 | ||
1896 | len_mapped_single_call = lcl_fm_ext[ext_count-1].fe_logical - | |
1897 | lun_start + lcl_fm_ext[ext_count - 1].fe_length; | |
1898 | ||
1899 | /* Have we finished mapping on this device? */ | |
1900 | if (req_fm_len <= len_mapped_single_call) | |
1901 | ost_done = 1; | |
1902 | ||
1903 | /* Clear the EXTENT_LAST flag which can be present on | |
1904 | * last extent */ | |
1905 | if (lcl_fm_ext[ext_count-1].fe_flags & FIEMAP_EXTENT_LAST) | |
1906 | lcl_fm_ext[ext_count - 1].fe_flags &= | |
1907 | ~FIEMAP_EXTENT_LAST; | |
1908 | ||
1909 | curr_loc = lov_stripe_size(lsm, | |
1910 | lcl_fm_ext[ext_count - 1].fe_logical+ | |
1911 | lcl_fm_ext[ext_count - 1].fe_length, | |
1912 | cur_stripe); | |
1913 | if (curr_loc >= fm_key->oa.o_size) | |
1914 | ost_eof = 1; | |
1915 | ||
1916 | fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext, | |
1917 | ost_index, ext_count, | |
1918 | current_extent); | |
1919 | ||
1920 | current_extent += ext_count; | |
1921 | ||
1922 | /* Ran out of available extents? */ | |
1923 | if (current_extent >= fiemap->fm_extent_count) | |
1924 | goto finish; | |
1925 | } while (ost_done == 0 && ost_eof == 0); | |
1926 | ||
1927 | if (cur_stripe_wrap == last_stripe) | |
1928 | goto finish; | |
1929 | } | |
1930 | ||
1931 | finish: | |
1932 | /* Indicate that we are returning device offsets unless file just has | |
1933 | * single stripe */ | |
1934 | if (lsm->lsm_stripe_count > 1) | |
1935 | fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER; | |
1936 | ||
1937 | if (get_num_extents) | |
1938 | goto skip_last_device_calc; | |
1939 | ||
1940 | /* Check if we have reached the last stripe and whether mapping for that | |
1941 | * stripe is done. */ | |
1942 | if (cur_stripe_wrap == last_stripe) { | |
1943 | if (ost_done || ost_eof) | |
1944 | fiemap->fm_extents[current_extent - 1].fe_flags |= | |
1945 | FIEMAP_EXTENT_LAST; | |
1946 | } | |
1947 | ||
1948 | skip_last_device_calc: | |
1949 | fiemap->fm_mapped_extents = current_extent; | |
1950 | ||
1951 | out: | |
1952 | OBD_FREE_LARGE(fm_local, buffer_size); | |
1953 | return rc; | |
1954 | } | |
1955 | ||
1956 | static int lov_get_info(const struct lu_env *env, struct obd_export *exp, | |
1957 | __u32 keylen, void *key, __u32 *vallen, void *val, | |
1958 | struct lov_stripe_md *lsm) | |
1959 | { | |
1960 | struct obd_device *obddev = class_exp2obd(exp); | |
1961 | struct lov_obd *lov = &obddev->u.lov; | |
1962 | int i, rc; | |
d7e09d03 PT |
1963 | |
1964 | if (!vallen || !val) | |
0a3bdb00 | 1965 | return -EFAULT; |
d7e09d03 PT |
1966 | |
1967 | obd_getref(obddev); | |
1968 | ||
1969 | if (KEY_IS(KEY_LOCK_TO_STRIPE)) { | |
1970 | struct { | |
1971 | char name[16]; | |
1972 | struct ldlm_lock *lock; | |
1973 | } *data = key; | |
1974 | struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name; | |
1975 | struct lov_oinfo *loi; | |
1976 | __u32 *stripe = val; | |
1977 | ||
18751668 JL |
1978 | if (*vallen < sizeof(*stripe)) { |
1979 | rc = -EFAULT; | |
1980 | goto out; | |
1981 | } | |
d7e09d03 PT |
1982 | *vallen = sizeof(*stripe); |
1983 | ||
1984 | /* XXX This is another one of those bits that will need to | |
1985 | * change if we ever actually support nested LOVs. It uses | |
1986 | * the lock's export to find out which stripe it is. */ | |
1987 | /* XXX - it's assumed all the locks for deleted OSTs have | |
1988 | * been cancelled. Also, the export for deleted OSTs will | |
1989 | * be NULL and won't match the lock's export. */ | |
1990 | for (i = 0; i < lsm->lsm_stripe_count; i++) { | |
1991 | loi = lsm->lsm_oinfo[i]; | |
1992 | if (!lov->lov_tgts[loi->loi_ost_idx]) | |
1993 | continue; | |
1994 | if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp == | |
1995 | data->lock->l_conn_export && | |
1996 | ostid_res_name_eq(&loi->loi_oi, res_id)) { | |
1997 | *stripe = i; | |
18751668 JL |
1998 | rc = 0; |
1999 | goto out; | |
d7e09d03 PT |
2000 | } |
2001 | } | |
2002 | LDLM_ERROR(data->lock, "lock on inode without such object"); | |
2003 | dump_lsm(D_ERROR, lsm); | |
18751668 JL |
2004 | rc = -ENXIO; |
2005 | goto out; | |
d7e09d03 PT |
2006 | } else if (KEY_IS(KEY_LAST_ID)) { |
2007 | struct obd_id_info *info = val; | |
21aef7d9 | 2008 | __u32 size = sizeof(u64); |
d7e09d03 PT |
2009 | struct lov_tgt_desc *tgt; |
2010 | ||
2011 | LASSERT(*vallen == sizeof(struct obd_id_info)); | |
2012 | tgt = lov->lov_tgts[info->idx]; | |
2013 | ||
18751668 JL |
2014 | if (!tgt || !tgt->ltd_active) { |
2015 | rc = -ESRCH; | |
2016 | goto out; | |
2017 | } | |
d7e09d03 PT |
2018 | |
2019 | rc = obd_get_info(env, tgt->ltd_exp, keylen, key, | |
2020 | &size, info->data, NULL); | |
18751668 JL |
2021 | rc = 0; |
2022 | goto out; | |
d7e09d03 PT |
2023 | } else if (KEY_IS(KEY_LOVDESC)) { |
2024 | struct lov_desc *desc_ret = val; | |
2025 | *desc_ret = lov->desc; | |
2026 | ||
18751668 JL |
2027 | rc = 0; |
2028 | goto out; | |
d7e09d03 PT |
2029 | } else if (KEY_IS(KEY_FIEMAP)) { |
2030 | rc = lov_fiemap(lov, keylen, key, vallen, val, lsm); | |
18751668 | 2031 | goto out; |
d7e09d03 PT |
2032 | } else if (KEY_IS(KEY_CONNECT_FLAG)) { |
2033 | struct lov_tgt_desc *tgt; | |
bcc3b704 | 2034 | __u64 ost_idx = *((__u64 *)val); |
d7e09d03 PT |
2035 | |
2036 | LASSERT(*vallen == sizeof(__u64)); | |
2037 | LASSERT(ost_idx < lov->desc.ld_tgt_count); | |
2038 | tgt = lov->lov_tgts[ost_idx]; | |
2039 | ||
18751668 JL |
2040 | if (!tgt || !tgt->ltd_exp) { |
2041 | rc = -ESRCH; | |
2042 | goto out; | |
2043 | } | |
d7e09d03 PT |
2044 | |
2045 | *((__u64 *)val) = exp_connect_flags(tgt->ltd_exp); | |
18751668 JL |
2046 | rc = 0; |
2047 | goto out; | |
d7e09d03 PT |
2048 | } else if (KEY_IS(KEY_TGT_COUNT)) { |
2049 | *((int *)val) = lov->desc.ld_tgt_count; | |
18751668 JL |
2050 | rc = 0; |
2051 | goto out; | |
d7e09d03 PT |
2052 | } |
2053 | ||
2054 | rc = -EINVAL; | |
2055 | ||
2056 | out: | |
2057 | obd_putref(obddev); | |
0a3bdb00 | 2058 | return rc; |
d7e09d03 PT |
2059 | } |
2060 | ||
2061 | static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp, | |
21aef7d9 | 2062 | u32 keylen, void *key, u32 vallen, |
d7e09d03 PT |
2063 | void *val, struct ptlrpc_request_set *set) |
2064 | { | |
2065 | struct obd_device *obddev = class_exp2obd(exp); | |
2066 | struct lov_obd *lov = &obddev->u.lov; | |
21aef7d9 | 2067 | u32 count; |
d7e09d03 PT |
2068 | int i, rc = 0, err; |
2069 | struct lov_tgt_desc *tgt; | |
2070 | unsigned incr, check_uuid, | |
2071 | do_inactive, no_set; | |
2072 | unsigned next_id = 0, mds_con = 0, capa = 0; | |
d7e09d03 PT |
2073 | |
2074 | incr = check_uuid = do_inactive = no_set = 0; | |
2075 | if (set == NULL) { | |
2076 | no_set = 1; | |
2077 | set = ptlrpc_prep_set(); | |
2078 | if (!set) | |
0a3bdb00 | 2079 | return -ENOMEM; |
d7e09d03 PT |
2080 | } |
2081 | ||
2082 | obd_getref(obddev); | |
2083 | count = lov->desc.ld_tgt_count; | |
2084 | ||
2085 | if (KEY_IS(KEY_NEXT_ID)) { | |
2086 | count = vallen / sizeof(struct obd_id_info); | |
21aef7d9 | 2087 | vallen = sizeof(u64); |
d7e09d03 PT |
2088 | incr = sizeof(struct obd_id_info); |
2089 | do_inactive = 1; | |
2090 | next_id = 1; | |
2091 | } else if (KEY_IS(KEY_CHECKSUM)) { | |
2092 | do_inactive = 1; | |
2093 | } else if (KEY_IS(KEY_EVICT_BY_NID)) { | |
2094 | /* use defaults: do_inactive = incr = 0; */ | |
2095 | } else if (KEY_IS(KEY_MDS_CONN)) { | |
2096 | mds_con = 1; | |
2097 | } else if (KEY_IS(KEY_CAPA_KEY)) { | |
2098 | capa = 1; | |
2099 | } else if (KEY_IS(KEY_CACHE_SET)) { | |
2100 | LASSERT(lov->lov_cache == NULL); | |
2101 | lov->lov_cache = val; | |
2102 | do_inactive = 1; | |
2103 | } | |
2104 | ||
2105 | for (i = 0; i < count; i++, val = (char *)val + incr) { | |
2106 | if (next_id) { | |
bcc3b704 | 2107 | tgt = lov->lov_tgts[((struct obd_id_info *)val)->idx]; |
d7e09d03 PT |
2108 | } else { |
2109 | tgt = lov->lov_tgts[i]; | |
2110 | } | |
2111 | /* OST was disconnected */ | |
2112 | if (!tgt || !tgt->ltd_exp) | |
2113 | continue; | |
2114 | ||
2115 | /* OST is inactive and we don't want inactive OSCs */ | |
2116 | if (!tgt->ltd_active && !do_inactive) | |
2117 | continue; | |
2118 | ||
2119 | if (mds_con) { | |
2120 | struct mds_group_info *mgi; | |
2121 | ||
2122 | LASSERT(vallen == sizeof(*mgi)); | |
2123 | mgi = (struct mds_group_info *)val; | |
2124 | ||
2125 | /* Only want a specific OSC */ | |
2126 | if (mgi->uuid && !obd_uuid_equals(mgi->uuid, | |
2127 | &tgt->ltd_uuid)) | |
2128 | continue; | |
2129 | ||
2130 | err = obd_set_info_async(env, tgt->ltd_exp, | |
2131 | keylen, key, sizeof(int), | |
2132 | &mgi->group, set); | |
2133 | } else if (next_id) { | |
2134 | err = obd_set_info_async(env, tgt->ltd_exp, | |
2135 | keylen, key, vallen, | |
bcc3b704 | 2136 | ((struct obd_id_info *)val)->data, set); |
d7e09d03 | 2137 | } else if (capa) { |
bcc3b704 | 2138 | struct mds_capa_info *info = (struct mds_capa_info *)val; |
d7e09d03 PT |
2139 | |
2140 | LASSERT(vallen == sizeof(*info)); | |
2141 | ||
2142 | /* Only want a specific OSC */ | |
2143 | if (info->uuid && | |
2144 | !obd_uuid_equals(info->uuid, &tgt->ltd_uuid)) | |
2145 | continue; | |
2146 | ||
2147 | err = obd_set_info_async(env, tgt->ltd_exp, keylen, | |
2148 | key, sizeof(*info->capa), | |
2149 | info->capa, set); | |
2150 | } else { | |
2151 | /* Only want a specific OSC */ | |
2152 | if (check_uuid && | |
2153 | !obd_uuid_equals(val, &tgt->ltd_uuid)) | |
2154 | continue; | |
2155 | ||
2156 | err = obd_set_info_async(env, tgt->ltd_exp, | |
2157 | keylen, key, vallen, val, set); | |
2158 | } | |
2159 | ||
2160 | if (!rc) | |
2161 | rc = err; | |
2162 | } | |
2163 | ||
2164 | obd_putref(obddev); | |
2165 | if (no_set) { | |
2166 | err = ptlrpc_set_wait(set); | |
2167 | if (!rc) | |
2168 | rc = err; | |
2169 | ptlrpc_set_destroy(set); | |
2170 | } | |
0a3bdb00 | 2171 | return rc; |
d7e09d03 PT |
2172 | } |
2173 | ||
d7e09d03 | 2174 | void lov_stripe_lock(struct lov_stripe_md *md) |
82604f8c | 2175 | __acquires(&md->lsm_lock) |
d7e09d03 PT |
2176 | { |
2177 | LASSERT(md->lsm_lock_owner != current_pid()); | |
2178 | spin_lock(&md->lsm_lock); | |
2179 | LASSERT(md->lsm_lock_owner == 0); | |
2180 | md->lsm_lock_owner = current_pid(); | |
2181 | } | |
2182 | EXPORT_SYMBOL(lov_stripe_lock); | |
2183 | ||
2184 | void lov_stripe_unlock(struct lov_stripe_md *md) | |
82604f8c | 2185 | __releases(&md->lsm_lock) |
d7e09d03 PT |
2186 | { |
2187 | LASSERT(md->lsm_lock_owner == current_pid()); | |
2188 | md->lsm_lock_owner = 0; | |
2189 | spin_unlock(&md->lsm_lock); | |
2190 | } | |
2191 | EXPORT_SYMBOL(lov_stripe_unlock); | |
2192 | ||
2193 | static int lov_quotactl(struct obd_device *obd, struct obd_export *exp, | |
2194 | struct obd_quotactl *oqctl) | |
2195 | { | |
2196 | struct lov_obd *lov = &obd->u.lov; | |
2197 | struct lov_tgt_desc *tgt; | |
2198 | __u64 curspace = 0; | |
2199 | __u64 bhardlimit = 0; | |
2200 | int i, rc = 0; | |
d7e09d03 PT |
2201 | |
2202 | if (oqctl->qc_cmd != LUSTRE_Q_QUOTAON && | |
2203 | oqctl->qc_cmd != LUSTRE_Q_QUOTAOFF && | |
2204 | oqctl->qc_cmd != Q_GETOQUOTA && | |
2205 | oqctl->qc_cmd != Q_INITQUOTA && | |
2206 | oqctl->qc_cmd != LUSTRE_Q_SETQUOTA && | |
2207 | oqctl->qc_cmd != Q_FINVALIDATE) { | |
2208 | CERROR("bad quota opc %x for lov obd", oqctl->qc_cmd); | |
0a3bdb00 | 2209 | return -EFAULT; |
d7e09d03 PT |
2210 | } |
2211 | ||
2212 | /* for lov tgt */ | |
2213 | obd_getref(obd); | |
2214 | for (i = 0; i < lov->desc.ld_tgt_count; i++) { | |
2215 | int err; | |
2216 | ||
2217 | tgt = lov->lov_tgts[i]; | |
2218 | ||
2219 | if (!tgt) | |
2220 | continue; | |
2221 | ||
2222 | if (!tgt->ltd_active || tgt->ltd_reap) { | |
2223 | if (oqctl->qc_cmd == Q_GETOQUOTA && | |
2224 | lov->lov_tgts[i]->ltd_activate) { | |
2225 | rc = -EREMOTEIO; | |
2226 | CERROR("ost %d is inactive\n", i); | |
2227 | } else { | |
2228 | CDEBUG(D_HA, "ost %d is inactive\n", i); | |
2229 | } | |
2230 | continue; | |
2231 | } | |
2232 | ||
2233 | err = obd_quotactl(tgt->ltd_exp, oqctl); | |
2234 | if (err) { | |
2235 | if (tgt->ltd_active && !rc) | |
2236 | rc = err; | |
2237 | continue; | |
2238 | } | |
2239 | ||
2240 | if (oqctl->qc_cmd == Q_GETOQUOTA) { | |
2241 | curspace += oqctl->qc_dqblk.dqb_curspace; | |
2242 | bhardlimit += oqctl->qc_dqblk.dqb_bhardlimit; | |
2243 | } | |
2244 | } | |
2245 | obd_putref(obd); | |
2246 | ||
2247 | if (oqctl->qc_cmd == Q_GETOQUOTA) { | |
2248 | oqctl->qc_dqblk.dqb_curspace = curspace; | |
2249 | oqctl->qc_dqblk.dqb_bhardlimit = bhardlimit; | |
2250 | } | |
0a3bdb00 | 2251 | return rc; |
d7e09d03 PT |
2252 | } |
2253 | ||
2254 | static int lov_quotacheck(struct obd_device *obd, struct obd_export *exp, | |
2255 | struct obd_quotactl *oqctl) | |
2256 | { | |
2257 | struct lov_obd *lov = &obd->u.lov; | |
2258 | int i, rc = 0; | |
d7e09d03 PT |
2259 | |
2260 | obd_getref(obd); | |
2261 | ||
2262 | for (i = 0; i < lov->desc.ld_tgt_count; i++) { | |
2263 | if (!lov->lov_tgts[i]) | |
2264 | continue; | |
2265 | ||
2266 | /* Skip quota check on the administratively disabled OSTs. */ | |
2267 | if (!lov->lov_tgts[i]->ltd_activate) { | |
2268 | CWARN("lov idx %d was administratively disabled, " | |
2269 | "skip quotacheck on it.\n", i); | |
2270 | continue; | |
2271 | } | |
2272 | ||
2273 | if (!lov->lov_tgts[i]->ltd_active) { | |
2274 | CERROR("lov idx %d inactive\n", i); | |
2275 | rc = -EIO; | |
2276 | goto out; | |
2277 | } | |
2278 | } | |
2279 | ||
2280 | for (i = 0; i < lov->desc.ld_tgt_count; i++) { | |
2281 | int err; | |
2282 | ||
2283 | if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_activate) | |
2284 | continue; | |
2285 | ||
2286 | err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl); | |
2287 | if (err && !rc) | |
2288 | rc = err; | |
2289 | } | |
2290 | ||
2291 | out: | |
2292 | obd_putref(obd); | |
2293 | ||
0a3bdb00 | 2294 | return rc; |
d7e09d03 PT |
2295 | } |
2296 | ||
2297 | struct obd_ops lov_obd_ops = { | |
2298 | .o_owner = THIS_MODULE, | |
2299 | .o_setup = lov_setup, | |
2300 | .o_precleanup = lov_precleanup, | |
2301 | .o_cleanup = lov_cleanup, | |
5e448831 | 2302 | /*.o_process_config = lov_process_config,*/ |
d7e09d03 PT |
2303 | .o_connect = lov_connect, |
2304 | .o_disconnect = lov_disconnect, | |
2305 | .o_statfs = lov_statfs, | |
2306 | .o_statfs_async = lov_statfs_async, | |
2307 | .o_packmd = lov_packmd, | |
2308 | .o_unpackmd = lov_unpackmd, | |
2309 | .o_create = lov_create, | |
2310 | .o_destroy = lov_destroy, | |
d7e09d03 | 2311 | .o_getattr_async = lov_getattr_async, |
d7e09d03 | 2312 | .o_setattr_async = lov_setattr_async, |
d7e09d03 | 2313 | .o_adjust_kms = lov_adjust_kms, |
d7e09d03 | 2314 | .o_find_cbdata = lov_find_cbdata, |
d7e09d03 PT |
2315 | .o_iocontrol = lov_iocontrol, |
2316 | .o_get_info = lov_get_info, | |
2317 | .o_set_info_async = lov_set_info_async, | |
d7e09d03 PT |
2318 | .o_notify = lov_notify, |
2319 | .o_pool_new = lov_pool_new, | |
2320 | .o_pool_rem = lov_pool_remove, | |
2321 | .o_pool_add = lov_pool_add, | |
2322 | .o_pool_del = lov_pool_del, | |
2323 | .o_getref = lov_getref, | |
2324 | .o_putref = lov_putref, | |
2325 | .o_quotactl = lov_quotactl, | |
2326 | .o_quotacheck = lov_quotacheck, | |
2327 | }; | |
2328 | ||
2329 | struct kmem_cache *lov_oinfo_slab; | |
2330 | ||
d7e09d03 PT |
2331 | int __init lov_init(void) |
2332 | { | |
e6be8e63 | 2333 | struct lprocfs_static_vars lvars = { NULL }; |
d7e09d03 | 2334 | int rc; |
d7e09d03 PT |
2335 | |
2336 | /* print an address of _any_ initialized kernel symbol from this | |
2337 | * module, to allow debugging with gdb that doesn't support data | |
2338 | * symbols from modules.*/ | |
2339 | CDEBUG(D_INFO, "Lustre LOV module (%p).\n", &lov_caches); | |
2340 | ||
2341 | rc = lu_kmem_init(lov_caches); | |
2342 | if (rc) | |
2343 | return rc; | |
2344 | ||
2345 | lov_oinfo_slab = kmem_cache_create("lov_oinfo", | |
2346 | sizeof(struct lov_oinfo), | |
2347 | 0, SLAB_HWCACHE_ALIGN, NULL); | |
2348 | if (lov_oinfo_slab == NULL) { | |
2349 | lu_kmem_fini(lov_caches); | |
2350 | return -ENOMEM; | |
2351 | } | |
2352 | lprocfs_lov_init_vars(&lvars); | |
2353 | ||
2354 | rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars, | |
2355 | LUSTRE_LOV_NAME, &lov_device_type); | |
2356 | ||
2357 | if (rc) { | |
2358 | kmem_cache_destroy(lov_oinfo_slab); | |
2359 | lu_kmem_fini(lov_caches); | |
2360 | } | |
2361 | ||
0a3bdb00 | 2362 | return rc; |
d7e09d03 PT |
2363 | } |
2364 | ||
2365 | static void /*__exit*/ lov_exit(void) | |
2366 | { | |
2367 | class_unregister_type(LUSTRE_LOV_NAME); | |
2368 | kmem_cache_destroy(lov_oinfo_slab); | |
2369 | ||
2370 | lu_kmem_fini(lov_caches); | |
2371 | } | |
2372 | ||
2373 | MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); | |
2374 | MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver"); | |
2375 | MODULE_LICENSE("GPL"); | |
6960736c | 2376 | MODULE_VERSION(LUSTRE_VERSION_STRING); |
d7e09d03 | 2377 | |
6960736c GKH |
2378 | module_init(lov_init); |
2379 | module_exit(lov_exit); |