1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Copyright (C) 2002 Cluster File Systems, Inc.
7 * Author: Phil Schwan <phil@off.net>
9 * This code is issued under the GNU General Public License.
10 * See the file COPYING in this distribution
14 #define DEBUG_SUBSYSTEM S_LOV
16 #include <linux/slab.h>
17 #include <linux/module.h>
18 #include <linux/obd_support.h>
19 #include <linux/lustre_lib.h>
20 #include <linux/lustre_net.h>
21 #include <linux/lustre_idl.h>
22 #include <linux/obd_class.h>
23 #include <linux/obd_lov.h>
25 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
29 static int lov_connect(struct lustre_handle *conn, struct obd_device *obd)
31 struct ptlrpc_request *req;
32 struct lov_obd *lov = &obd->u.lov;
33 struct lustre_handle mdc_conn;
39 rc = class_connect(conn, obd);
45 rc = obd_connect(&mdc_conn, lov->mdcobd);
47 CERROR("cannot connect to mdc: rc = %d\n", rc);
48 GOTO(out, rc = -EINVAL);
51 rc = mdc_getlovinfo(obd, &mdc_conn, &uuidarray, &req);
52 obd_disconnect(&mdc_conn);
55 CERROR("cannot get lov info %d\n", rc);
60 if (lov->desc.ld_tgt_count > 1000) {
61 CERROR("configuration error: target count > 1000 (%d)\n",
62 lov->desc.ld_tgt_count);
63 GOTO(out, rc = -EINVAL);
66 if (strcmp(obd->obd_uuid, lov->desc.ld_uuid)) {
67 CERROR("lov uuid %s not on mds device (%s)\n",
68 obd->obd_uuid, lov->desc.ld_uuid);
69 GOTO(out, rc = -EINVAL);
72 if (req->rq_repmsg->bufcount < 2 || req->rq_repmsg->buflens[1] <
73 sizeof(uuid_t) * lov->desc.ld_tgt_count) {
74 CERROR("invalid uuid array returned\n");
75 GOTO(out, rc = -EINVAL);
78 lov->bufsize = sizeof(struct lov_tgt_desc) * lov->desc.ld_tgt_count;
79 OBD_ALLOC(lov->tgts, lov->bufsize);
81 CERROR("Out of memory\n");
82 GOTO(out, rc = -ENOMEM);
85 uuidarray = lustre_msg_buf(req->rq_repmsg, 1);
86 for (i = 0 ; i < lov->desc.ld_tgt_count; i++)
87 memcpy(lov->tgts[i].uuid, uuidarray[i], sizeof(uuid_t));
89 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
90 struct obd_device *tgt = class_uuid2obd(uuidarray[i]);
92 CERROR("Target %s not configured\n", uuidarray[i]);
93 GOTO(out_mem, rc = -EINVAL);
95 rc = obd_connect(&lov->tgts[i].conn, tgt);
97 CERROR("Target %s connect error %d\n",
105 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
107 rc2 = obd_disconnect(&lov->tgts[i].conn);
109 CERROR("BAD: Target %s disconnect error %d\n",
112 OBD_FREE(lov->tgts, lov->bufsize);
116 class_disconnect(conn);
118 ptlrpc_free_req(req);
122 static int lov_disconnect(struct lustre_handle *conn)
124 struct obd_device *obd = class_conn2obd(conn);
125 struct lov_obd *lov = &obd->u.lov;
132 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
133 rc = obd_disconnect(&lov->tgts[i].conn);
135 CERROR("Target %s disconnect error %d\n",
136 lov->tgts[i].uuid, rc);
140 OBD_FREE(lov->tgts, lov->bufsize);
146 rc = class_disconnect(conn);
153 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
155 struct obd_ioctl_data* data = buf;
156 struct lov_obd *lov = &obd->u.lov;
160 if (data->ioc_inllen1 < 1) {
161 CERROR("osc setup requires an MDC UUID\n");
165 if (data->ioc_inllen1 > 37) {
166 CERROR("mdc UUID must be less than 38 characters\n");
170 /* FIXME: we should make a connection instead perhaps to avoid
171 the mdc from walking away? The fs guarantees this. */
172 lov->mdcobd = class_uuid2obd(data->ioc_inlbuf1);
174 CERROR("LOV %s cannot locate MDC %s\n", obd->obd_uuid,
182 static inline int lov_stripe_md_size(struct obd_device *obd)
184 struct lov_obd *lov = &obd->u.lov;
187 size = sizeof(struct lov_stripe_md) +
188 lov->desc.ld_tgt_count * sizeof(struct lov_object_id);
192 static int lov_create(struct lustre_handle *conn, struct obdo *oa, struct lov_stripe_md **ea)
196 struct obd_export *export = class_conn2export(conn);
198 struct lov_stripe_md *md;
202 CERROR("lov_create needs EA for striping information\n");
208 lov = &export->exp_obd->u.lov;
210 oa->o_easize = lov_stripe_md_size(export->exp_obd);
212 OBD_ALLOC(*ea, oa->o_easize);
218 md->lmd_size = oa->o_easize;
219 md->lmd_object_id = oa->o_id;
220 if (!md->lmd_stripe_count) {
221 md->lmd_stripe_count = lov->desc.ld_default_stripecount;
224 for (i = 0; i < md->lmd_stripe_count; i++) {
225 struct lov_stripe_md obj_md;
226 struct lov_stripe_md *obj_mdp = &obj_md;
227 /* create data objects with "parent" OA */
228 memcpy(&tmp, oa, sizeof(tmp));
229 tmp.o_easize = sizeof(struct lov_stripe_md);
230 rc = obd_create(&lov->tgts[i].conn, &tmp, &obj_mdp);
232 GOTO(out_cleanup, rc);
233 md->lmd_objects[i].l_object_id = tmp.o_id;
239 for (i2 = 0 ; i2 < i ; i2++) {
240 /* destroy already created objects here */
241 tmp.o_id = md->lmd_objects[i].l_object_id;
242 rc2 = obd_destroy(&lov->tgts[i].conn, &tmp, NULL);
244 CERROR("Failed to remove object from target %d\n",
252 static int lov_destroy(struct lustre_handle *conn, struct obdo *oa,
253 struct lov_stripe_md *ea)
257 struct obd_export *export = class_conn2export(conn);
259 struct lov_stripe_md *md;
263 CERROR("LOV requires striping ea for desctruction\n");
267 if (!export || !export->exp_obd)
270 lov = &export->exp_obd->u.lov;
273 for (i = 0; i < md->lmd_stripe_count; i++) {
274 /* create data objects with "parent" OA */
275 memcpy(&tmp, oa, sizeof(tmp));
276 oa->o_id = md->lmd_objects[i].l_object_id;
277 rc = obd_destroy(&lov->tgts[i].conn, &tmp, NULL);
279 CERROR("Error destroying object %Ld on %d\n",
287 static int lov_getattr(struct lustre_handle *conn, struct obdo *oa)
292 if (!class_conn2export(conn))
295 rc = obd_getattr(&conn->oc_dev->obd_multi_conn[0], oa);
299 static int lov_setattr(struct lustre_handle *conn, struct obdo *oa)
304 if (!class_conn2export(conn))
307 for (i = 0; i < conn->oc_dev->obd_multi_count; i++) {
308 rc = obd_setattr(&conn->oc_dev->obd_multi_conn[i], oa);
311 else if (retval != rc)
312 CERROR("different results on multiple OBDs!\n");
318 static int lov_open(struct lustre_handle *conn, struct obdo *oa)
323 if (!class_conn2export(conn))
326 for (i = 0; i < conn->oc_dev->obd_multi_count; i++) {
327 rc = obd_open(&conn->oc_dev->obd_multi_conn[i], oa);
330 else if (retval != rc)
331 CERROR("different results on multiple OBDs!\n");
337 static int lov_close(struct lustre_handle *conn, struct obdo *oa)
342 if (!class_conn2export(conn))
345 for (i = 0; i < conn->oc_dev->obd_multi_count; i++) {
346 rc = obd_close(&conn->oc_dev->obd_multi_conn[i], oa);
349 else if (retval != rc)
350 CERROR("different results on multiple OBDs!\n");
358 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
359 * we can send this 'punch' to just the authoritative node and the nodes
360 * that the punch will affect. */
361 static int lov_punch(struct lustre_handle *conn, struct obdo *oa,
362 obd_size count, obd_off offset)
367 if (!class_conn2export(conn))
370 for (i = 0; i < conn->oc_dev->obd_multi_count; i++) {
371 rc = obd_punch(&conn->oc_dev->obd_multi_conn[i], oa, count,
375 else if (retval != rc)
376 CERROR("different results on multiple OBDs!\n");
382 struct lov_callback_data {
384 wait_queue_head waitq;
387 static void lov_read_callback(struct ptlrpc_bulk_desc *desc, void *data)
389 struct lov_callback_data *cb_data = data;
391 if (atomic_dec_and_test(&cb_data->count))
392 wake_up(&cb_data->waitq);
395 static int lov_read_check_status(struct lov_callback_data *cb_data)
398 if (sigismember(&(current->pending.signal), SIGKILL) ||
399 sigismember(&(current->pending.signal), SIGTERM) ||
400 sigismember(&(current->pending.signal), SIGINT)) {
401 cb_data->flags |= PTL_RPC_FL_INTR;
404 if (atomic_read(&cb_data->count) == 0)
409 /* buffer must lie in user memory here */
410 static int lov_brw(int cmd, struct lustre_handle *conn, obd_count num_oa,
412 obd_count *oa_bufs, struct page **buf,
413 obd_size *count, obd_off *offset, obd_flag *flags,
414 bulk_callback_t callback, void *data)
416 int rc, i, page_array_offset = 0;
417 obd_off off = offset;
419 struct lov_callback_data *cb_data;
425 if (!class_conn2export(conn))
428 OBD_ALLOC(cb_data, sizeof(*cb_data));
429 if (cb_data == NULL) {
433 INIT_WAITQUEUE_HEAD(&cb_data->waitq);
434 atomic_set(&cb_data->count, 0);
436 for (i = 0; i < oa_bufs[0]; i++) {
437 struct page *current_page = buf[i];
439 struct lov_md *md = (struct lov_md *)oa[i]->inline;
440 int bufcount = oa_bufs[i];
441 // md->lmd_stripe_count
443 for (k = page_array_offset; k < bufcount + page_array_offset;
447 page_array_offset += bufcount;
450 while (off < offset + count) {
454 stripe = off / conn->oc_dev->u.lov.lov_stripe_size;
455 size = (stripe + 1) * conn->oc_dev->u.lov.lov_strip_size - off;
459 conn = stripe % conn->oc_dev->obd_multi_count;
462 atomic_inc(&cb_data->count);
463 rc = obd_brw(cmd, &conn->oc_dev->obd_multi_conn[conn],
465 &size, off, lov_read_callback, cb_data);
469 CERROR("read(off=%Lu, count=%Lu): %d\n",
470 (unsigned long long)off,
471 (unsigned long long)size, rc);
478 wait_event(&cb_data->waitq, lov_read_check_status(cb_data));
479 if (cb_data->flags & PTL_RPC_FL_INTR)
482 /* FIXME: The error handling here sucks */
484 OBD_FREE(cb_data, sizeof(*cb_data));
488 static void lov_write_finished(struct ptlrpc_bulk_desc *desc, void *data)
493 /* buffer must lie in user memory here */
494 static int filter_write(struct lustre_handle *conn, struct obdo *oa, char *buf,
495 obd_size *count, obd_off offset)
499 unsigned long retval;
502 if (!class_conn2export(conn)) {
503 CDEBUG(D_IOCTL, "invalid client %u\n", conn->oc_id);
508 file = filter_obj_open(conn->oc_dev, oa->o_id, oa->o_mode);
509 if (!file || IS_ERR(file)) {
511 return -PTR_ERR(file);
514 /* count doubles as retval */
515 retval = file->f_op->write(file, buf, *count, (loff_t *)&offset);
531 static int lov_enqueue(struct lustre_handle *conn, struct ldlm_namespace *ns,
532 struct ldlm_handle *parent_lock, __u64 *res_id,
533 __u32 type, struct ldlm_extent *extent, __u32 mode,
534 int *flags, void *data, int datalen,
535 struct ldlm_handle *lockh)
540 if (!class_conn2export(conn))
543 rc = obd_enqueue(&conn->oc_dev->obd_multi_conn[0], ns, parent_lock,
544 res_id, type, extent, mode, flags, data, datalen,
549 static int lov_cancel(struct lustre_handle *conn, __u32 mode,
550 struct ldlm_handle *lockh)
555 if (!class_conn2export(conn))
558 rc = obd_cancel(&conn->oc_dev->obd_multi_conn[0], oa);
563 struct obd_ops lov_obd_ops = {
565 o_connect: lov_connect,
566 o_disconnect: lov_disconnect,
567 o_create: lov_create,
568 o_destroy: lov_destroy,
570 o_getattr: lov_getattr,
571 o_setattr: lov_setattr,
574 o_brw: lov_pgcache_brw,
576 o_enqueue: lov_enqueue,
582 #define LOV_VERSION "v0.1"
584 static int __init lov_init(void)
586 printk(KERN_INFO "Lustre Logical Object Volume driver " LOV_VERSION
587 ", info@clusterfs.com\n");
588 return class_register_type(&lov_obd_ops, OBD_LOV_DEVICENAME);
591 static void __exit lov_exit(void)
593 class_unregister_type(OBD_LOV_DEVICENAME);
596 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
597 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver v0.1");
598 MODULE_LICENSE("GPL");
600 module_init(lov_init);
601 module_exit(lov_exit);