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_getinfo(struct obd_device *obd, struct lov_desc *desc,
30 uuid_t **uuids, struct ptlrpc_request **request)
32 struct ptlrpc_request *req;
33 struct mds_status_req *streq;
34 struct lov_obd *lov = &obd->u.lov;
35 struct mdc_obd *mdc = &lov->mdcobd->u.mdc;
36 int rc, size[2] = {sizeof(*streq)};
39 #warning error: need to set lov->mdc_connh somewhere!!!!
40 req = ptlrpc_prep_req2(mdc->mdc_client, mdc->mdc_conn, &lov->mdc_connh,
41 MDS_LOVINFO, 1, size, NULL);
43 GOTO(out, rc = -ENOMEM);
46 streq = lustre_msg_buf(req->rq_reqmsg, 0);
47 streq->flags = HTON__u32(MDS_STATUS_LOV);
48 streq->repbuf = HTON__u32(8000);
50 /* prepare for reply */
51 req->rq_level = LUSTRE_CONN_CON;
52 size[0] = sizeof(*desc);
54 req->rq_replen = lustre_msg_size(2, size);
56 rc = ptlrpc_queue_wait(req);
57 rc = ptlrpc_check_status(req, rc);
60 memcpy(desc, lustre_msg_buf(req->rq_repmsg, 0), sizeof(*desc));
61 *uuids = lustre_msg_buf(req->rq_repmsg, 1);
64 mdc->mdc_max_mdsize = sizeof(*desc) +
65 desc->ld_tgt_count * sizeof(uuid_t);
72 static int lov_connect(struct lustre_handle *conn, struct obd_device *obd)
76 struct ptlrpc_request *req;
77 struct lov_obd *lov = &obd->u.lov;
81 rc = class_connect(conn, obd);
87 rc = lov_getinfo(obd, &lov->desc, &uuidarray, &req);
89 CERROR("cannot get lov info %d\n", rc);
93 if (lov->desc.ld_tgt_count > 1000) {
94 CERROR("configuration error: target count > 1000 (%d)\n",
95 lov->desc.ld_tgt_count);
96 GOTO(out, rc = -EINVAL);
99 if (strcmp(obd->obd_uuid, lov->desc.ld_uuid)) {
100 CERROR("lov uuid %s not on mds device (%s)\n",
101 obd->obd_uuid, lov->desc.ld_uuid);
102 GOTO(out, rc = -EINVAL);
105 if (req->rq_repmsg->bufcount < 2 || req->rq_repmsg->buflens[1] <
106 sizeof(uuid_t) * lov->desc.ld_tgt_count) {
107 CERROR("invalid uuid array returned\n");
108 GOTO(out, rc = -EINVAL);
111 lov->bufsize = sizeof(struct lov_tgt_desc) * lov->desc.ld_tgt_count;
112 OBD_ALLOC(lov->tgts, lov->bufsize);
114 CERROR("Out of memory\n");
115 GOTO(out, rc = -ENOMEM);
118 uuidarray = lustre_msg_buf(req->rq_repmsg, 1);
119 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
120 memcpy(lov->tgts[i].uuid, uuidarray[i], sizeof(uuid_t));
123 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
124 struct obd_device *tgt = class_uuid2obd(uuidarray[i]);
126 CERROR("Target %s not configured\n", uuidarray[i]);
127 GOTO(out_mem, rc = -EINVAL);
129 rc = obd_connect(&lov->tgts[i].conn, tgt);
131 CERROR("Target %s connect error %d\n",
139 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
141 rc2 = obd_disconnect(&lov->tgts[i].conn);
143 CERROR("BAD: Target %s disconnect error %d\n",
146 OBD_FREE(lov->tgts, lov->bufsize);
150 class_disconnect(conn);
153 ptlrpc_free_req(req);
158 static int lov_disconnect(struct lustre_handle *conn)
160 struct obd_device *obd = class_conn2obd(conn);
161 struct lov_obd *lov = &obd->u.lov;
168 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
169 rc = obd_disconnect(&lov->tgts[i].conn);
171 CERROR("Target %s disconnect error %d\n",
172 lov->tgts[i].uuid, rc);
176 OBD_FREE(lov->tgts, lov->bufsize);
182 rc = class_disconnect(conn);
189 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
191 struct obd_ioctl_data* data = buf;
192 struct lov_obd *lov = &obd->u.lov;
196 if (data->ioc_inllen1 < 1) {
197 CERROR("osc setup requires an MDC UUID\n");
201 if (data->ioc_inllen1 > 37) {
202 CERROR("mdc UUID must be less than 38 characters\n");
206 /* FIXME: we should make a connection instead perhaps to avoid
207 the mdc from walking away? The fs guarantees this. */
208 lov->mdcobd = class_uuid2obd(data->ioc_inlbuf1);
210 CERROR("LOV %s cannot locate MDC %s\n", obd->obd_uuid,
218 static inline int lov_stripe_md_size(struct obd_device *obd)
220 struct lov_obd *lov = &obd->u.lov;
223 size = sizeof(struct lov_stripe_md) +
224 lov->desc.ld_tgt_count * sizeof(struct lov_object_id);
228 static int lov_create(struct lustre_handle *conn, struct obdo *oa, struct lov_stripe_md **ea)
232 struct obd_export *export = class_conn2export(conn);
234 struct lov_stripe_md *md;
238 CERROR("lov_create needs EA for striping information\n");
244 lov = &export->export_obd->u.lov;
246 oa->o_easize = lov_stripe_md_size(export->export_obd);
248 OBD_ALLOC(*ea, oa->o_easize);
254 md->lmd_size = oa->o_easize;
255 md->lmd_object_id = oa->o_id;
256 if (!md->lmd_stripe_count) {
257 md->lmd_stripe_count = lov->desc.ld_default_stripecount;
260 for (i = 0; i < md->lmd_stripe_count; i++) {
261 struct lov_stripe_md obj_md;
262 struct lov_stripe_md *obj_mdp = &obj_md;
263 /* create data objects with "parent" OA */
264 memcpy(&tmp, oa, sizeof(tmp));
265 tmp.o_easize = sizeof(struct lov_stripe_md);
266 rc = obd_create(&lov->tgts[i].conn, &tmp, &obj_mdp);
268 GOTO(out_cleanup, rc);
269 md->lmd_objects[i].l_object_id = tmp.o_id;
275 for (i2 = 0 ; i2 < i ; i2++) {
276 /* destroy already created objects here */
277 tmp.o_id = md->lmd_objects[i].l_object_id;
278 rc2 = obd_destroy(&lov->tgts[i].conn, &tmp, NULL);
280 CERROR("Failed to remove object from target %d\n",
288 static int lov_destroy(struct lustre_handle *conn, struct obdo *oa,
289 struct lov_stripe_md *ea)
293 struct obd_export *export = class_conn2export(conn);
295 struct lov_stripe_md *md;
299 CERROR("LOV requires striping ea for desctruction\n");
303 if (!export || !export->export_obd)
306 lov = &export->export_obd->u.lov;
309 for (i = 0; i < md->lmd_stripe_count; i++) {
310 /* create data objects with "parent" OA */
311 memcpy(&tmp, oa, sizeof(tmp));
312 oa->o_id = md->lmd_objects[i].l_object_id;
313 rc = obd_destroy(&lov->tgts[i].conn, &tmp, NULL);
315 CERROR("Error destroying object %Ld on %d\n",
323 static int lov_getattr(struct lustre_handle *conn, struct obdo *oa)
328 if (!class_conn2export(conn))
331 rc = obd_getattr(&conn->oc_dev->obd_multi_conn[0], oa);
335 static int lov_setattr(struct lustre_handle *conn, struct obdo *oa)
340 if (!class_conn2export(conn))
343 for (i = 0; i < conn->oc_dev->obd_multi_count; i++) {
344 rc = obd_setattr(&conn->oc_dev->obd_multi_conn[i], oa);
347 else if (retval != rc)
348 CERROR("different results on multiple OBDs!\n");
354 static int lov_open(struct lustre_handle *conn, struct obdo *oa)
359 if (!class_conn2export(conn))
362 for (i = 0; i < conn->oc_dev->obd_multi_count; i++) {
363 rc = obd_open(&conn->oc_dev->obd_multi_conn[i], oa);
366 else if (retval != rc)
367 CERROR("different results on multiple OBDs!\n");
373 static int lov_close(struct lustre_handle *conn, struct obdo *oa)
378 if (!class_conn2export(conn))
381 for (i = 0; i < conn->oc_dev->obd_multi_count; i++) {
382 rc = obd_close(&conn->oc_dev->obd_multi_conn[i], oa);
385 else if (retval != rc)
386 CERROR("different results on multiple OBDs!\n");
394 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
395 * we can send this 'punch' to just the authoritative node and the nodes
396 * that the punch will affect. */
397 static int lov_punch(struct lustre_handle *conn, struct obdo *oa,
398 obd_size count, obd_off offset)
403 if (!class_conn2export(conn))
406 for (i = 0; i < conn->oc_dev->obd_multi_count; i++) {
407 rc = obd_punch(&conn->oc_dev->obd_multi_conn[i], oa, count,
411 else if (retval != rc)
412 CERROR("different results on multiple OBDs!\n");
418 struct lov_callback_data {
420 wait_queue_head waitq;
423 static void lov_read_callback(struct ptlrpc_bulk_desc *desc, void *data)
425 struct lov_callback_data *cb_data = data;
427 if (atomic_dec_and_test(&cb_data->count))
428 wake_up(&cb_data->waitq);
431 static int lov_read_check_status(struct lov_callback_data *cb_data)
434 if (sigismember(&(current->pending.signal), SIGKILL) ||
435 sigismember(&(current->pending.signal), SIGTERM) ||
436 sigismember(&(current->pending.signal), SIGINT)) {
437 cb_data->flags |= PTL_RPC_FL_INTR;
440 if (atomic_read(&cb_data->count) == 0)
445 /* buffer must lie in user memory here */
446 static int lov_brw(int cmd, struct lustre_handle *conn, obd_count num_oa,
448 obd_count *oa_bufs, struct page **buf,
449 obd_size *count, obd_off *offset, obd_flag *flags,
450 bulk_callback_t callback, void *data)
452 int rc, i, page_array_offset = 0;
453 obd_off off = offset;
455 struct lov_callback_data *cb_data;
461 if (!class_conn2export(conn))
464 OBD_ALLOC(cb_data, sizeof(*cb_data));
465 if (cb_data == NULL) {
469 INIT_WAITQUEUE_HEAD(&cb_data->waitq);
470 atomic_set(&cb_data->count, 0);
472 for (i = 0; i < oa_bufs[0]; i++) {
473 struct page *current_page = buf[i];
475 struct lov_md *md = (struct lov_md *)oa[i]->inline;
476 int bufcount = oa_bufs[i];
477 // md->lmd_stripe_count
479 for (k = page_array_offset; k < bufcount + page_array_offset;
483 page_array_offset += bufcount;
486 while (off < offset + count) {
490 stripe = off / conn->oc_dev->u.lov.lov_stripe_size;
491 size = (stripe + 1) * conn->oc_dev->u.lov.lov_strip_size - off;
495 conn = stripe % conn->oc_dev->obd_multi_count;
498 atomic_inc(&cb_data->count);
499 rc = obd_brw(cmd, &conn->oc_dev->obd_multi_conn[conn],
501 &size, off, lov_read_callback, cb_data);
505 CERROR("read(off=%Lu, count=%Lu): %d\n",
506 (unsigned long long)off,
507 (unsigned long long)size, rc);
514 wait_event(&cb_data->waitq, lov_read_check_status(cb_data));
515 if (cb_data->flags & PTL_RPC_FL_INTR)
518 /* FIXME: The error handling here sucks */
520 OBD_FREE(cb_data, sizeof(*cb_data));
524 static void lov_write_finished(struct ptlrpc_bulk_desc *desc, void *data)
529 /* buffer must lie in user memory here */
530 static int filter_write(struct lustre_handle *conn, struct obdo *oa, char *buf,
531 obd_size *count, obd_off offset)
535 unsigned long retval;
538 if (!class_conn2export(conn)) {
539 CDEBUG(D_IOCTL, "invalid client %u\n", conn->oc_id);
544 file = filter_obj_open(conn->oc_dev, oa->o_id, oa->o_mode);
545 if (!file || IS_ERR(file)) {
547 return -PTR_ERR(file);
550 /* count doubles as retval */
551 retval = file->f_op->write(file, buf, *count, (loff_t *)&offset);
567 static int lov_enqueue(struct lustre_handle *conn, struct ldlm_namespace *ns,
568 struct ldlm_handle *parent_lock, __u64 *res_id,
569 __u32 type, struct ldlm_extent *extent, __u32 mode,
570 int *flags, void *data, int datalen,
571 struct ldlm_handle *lockh)
576 if (!class_conn2export(conn))
579 rc = obd_enqueue(&conn->oc_dev->obd_multi_conn[0], ns, parent_lock,
580 res_id, type, extent, mode, flags, data, datalen,
585 static int lov_cancel(struct lustre_handle *conn, __u32 mode,
586 struct ldlm_handle *lockh)
591 if (!class_conn2export(conn))
594 rc = obd_cancel(&conn->oc_dev->obd_multi_conn[0], oa);
599 struct obd_ops lov_obd_ops = {
601 o_connect: lov_connect,
602 o_disconnect: lov_disconnect,
603 o_create: lov_create,
604 o_destroy: lov_destroy,
606 o_getattr: lov_getattr,
607 o_setattr: lov_setattr,
610 o_brw: lov_pgcache_brw,
612 o_enqueue: lov_enqueue,
618 #define LOV_VERSION "v0.1"
620 static int __init lov_init(void)
622 printk(KERN_INFO "Lustre Logical Object Volume driver " LOV_VERSION
623 ", info@clusterfs.com\n");
624 return class_register_type(&lov_obd_ops, OBD_LOV_DEVICENAME);
627 static void __exit lov_exit(void)
629 class_unregister_type(OBD_LOV_DEVICENAME);
632 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
633 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver v0.1");
634 MODULE_LICENSE("GPL");
636 module_init(lov_init);
637 module_exit(lov_exit);