Whamcloud - gitweb
The noncontroversial portion of the last few days of changes:
[fs/lustre-release.git] / lustre / ost / ost_handler.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *   Author: Peter J. Braam <braam@clusterfs.com>
6  *   Author: Phil Schwan <phil@clusterfs.com>
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  *  Storage Target Handling functions
24  *  Lustre Object Server Module (OST)
25  *
26  *  This server is single threaded at present (but can easily be multi
27  *  threaded). For testing and management it is treated as an
28  *  obd_device, although it does not export a full OBD method table
29  *  (the requests are coming in over the wire, so object target
30  *  modules do not have a full method table.)
31  */
32
33 #define EXPORT_SYMTAB
34
35 #include <linux/version.h>
36 #include <linux/module.h>
37 #include <linux/fs.h>
38 #include <linux/stat.h>
39 #include <linux/locks.h>
40 #include <linux/ext2_fs.h>
41 #include <linux/quotaops.h>
42 #include <asm/unistd.h>
43
44 #define DEBUG_SUBSYSTEM S_OST
45
46 #include <linux/obd_ost.h>
47 #include <linux/lustre_net.h>
48
49 static int ost_destroy(struct ost_obd *ost, struct ptlrpc_request *req)
50 {
51         struct obd_conn conn;
52         struct ost_body *body;
53         int rc, size = sizeof(*body);
54         ENTRY;
55
56         body = lustre_msg_buf(req->rq_reqmsg, 0);
57         conn.oc_id = body->connid;
58         conn.oc_dev = ost->ost_tgt;
59
60         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
61         if (rc)
62                 RETURN(rc);
63
64         req->rq_status = obd_destroy(&conn, &body->oa);
65         RETURN(0);
66 }
67
68 static int ost_getattr(struct ost_obd *ost, struct ptlrpc_request *req)
69 {
70         struct obd_conn conn;
71         struct ost_body *body, *repbody;
72         int rc, size = sizeof(*body);
73         ENTRY;
74
75         body = lustre_msg_buf(req->rq_reqmsg, 0);
76         conn.oc_id = body->connid;
77         conn.oc_dev = ost->ost_tgt;
78
79         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
80         if (rc)
81                 RETURN(rc);
82
83         repbody = lustre_msg_buf(req->rq_repmsg, 0);
84         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
85         req->rq_status = obd_getattr(&conn, &repbody->oa);
86         RETURN(0);
87 }
88
89 static int ost_open(struct ost_obd *ost, struct ptlrpc_request *req)
90 {
91         struct obd_conn conn;
92         struct ost_body *body, *repbody;
93         int rc, size = sizeof(*body);
94         ENTRY;
95
96         body = lustre_msg_buf(req->rq_reqmsg, 0);
97         conn.oc_id = body->connid;
98         conn.oc_dev = ost->ost_tgt;
99
100         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
101         if (rc)
102                 RETURN(rc);
103
104         repbody = lustre_msg_buf(req->rq_repmsg, 0);
105         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
106         req->rq_status = obd_open(&conn, &repbody->oa);
107         RETURN(0);
108 }
109
110 static int ost_close(struct ost_obd *ost, struct ptlrpc_request *req)
111 {
112         struct obd_conn conn;
113         struct ost_body *body, *repbody;
114         int rc, size = sizeof(*body);
115         ENTRY;
116
117         body = lustre_msg_buf(req->rq_reqmsg, 0);
118         conn.oc_id = body->connid;
119         conn.oc_dev = ost->ost_tgt;
120
121         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
122         if (rc)
123                 RETURN(rc);
124
125         repbody = lustre_msg_buf(req->rq_repmsg, 0);
126         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
127         req->rq_status = obd_close(&conn, &repbody->oa);
128         RETURN(0);
129 }
130
131 static int ost_create(struct ost_obd *ost, struct ptlrpc_request *req)
132 {
133         struct obd_conn conn;
134         struct ost_body *body, *repbody;
135         int rc, size = sizeof(*body);
136         ENTRY;
137
138         body = lustre_msg_buf(req->rq_reqmsg, 0);
139         conn.oc_id = body->connid;
140         conn.oc_dev = ost->ost_tgt;
141
142         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
143         if (rc)
144                 RETURN(rc);
145
146         repbody = lustre_msg_buf(req->rq_repmsg, 0);
147         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
148         req->rq_status = obd_create(&conn, &repbody->oa);
149         RETURN(0);
150 }
151
152 static int ost_punch(struct ost_obd *ost, struct ptlrpc_request *req)
153 {
154         struct obd_conn conn;
155         struct ost_body *body, *repbody;
156         int rc, size = sizeof(*body);
157         ENTRY;
158
159         body = lustre_msg_buf(req->rq_reqmsg, 0);
160         conn.oc_id = body->connid;
161         conn.oc_dev = ost->ost_tgt;
162
163         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
164         if (rc)
165                 RETURN(rc);
166
167         repbody = lustre_msg_buf(req->rq_repmsg, 0);
168         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
169         req->rq_status = obd_punch(&conn, &repbody->oa,
170                                    repbody->oa.o_size, repbody->oa.o_blocks);
171         RETURN(0);
172 }
173
174 static int ost_setattr(struct ost_obd *ost, struct ptlrpc_request *req)
175 {
176         struct obd_conn conn;
177         struct ost_body *body, *repbody;
178         int rc, size = sizeof(*body);
179         ENTRY;
180
181         body = lustre_msg_buf(req->rq_reqmsg, 0);
182         conn.oc_id = body->connid;
183         conn.oc_dev = ost->ost_tgt;
184
185         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
186         if (rc)
187                 RETURN(rc);
188
189         repbody = lustre_msg_buf(req->rq_repmsg, 0);
190         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
191         req->rq_status = obd_setattr(&conn, &repbody->oa);
192         RETURN(0);
193 }
194
195 static int ost_connect(struct ost_obd *ost, struct ptlrpc_request *req)
196 {
197         struct obd_conn conn;
198         struct ost_body *body;
199         int rc, size = sizeof(*body);
200         ENTRY;
201
202         conn.oc_dev = ost->ost_tgt;
203
204         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
205         if (rc)
206                 RETURN(rc);
207
208         req->rq_status = obd_connect(&conn);
209
210         CDEBUG(D_IOCTL, "rep buffer %p, id %d\n", req->rq_repmsg, conn.oc_id);
211         body = lustre_msg_buf(req->rq_repmsg, 0);
212         body->connid = conn.oc_id;
213         RETURN(0);
214 }
215
216 static int ost_disconnect(struct ost_obd *ost, struct ptlrpc_request *req)
217 {
218         struct obd_conn conn;
219         struct ost_body *body;
220         int rc, size = sizeof(*body);
221         ENTRY;
222
223         body = lustre_msg_buf(req->rq_reqmsg, 0);
224         conn.oc_id = body->connid;
225         conn.oc_dev = ost->ost_tgt;
226
227         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
228         if (rc)
229                 RETURN(rc);
230
231         CDEBUG(D_IOCTL, "Disconnecting %d\n", conn.oc_id);
232         req->rq_status = obd_disconnect(&conn);
233         RETURN(0);
234 }
235
236 static int ost_get_info(struct ost_obd *ost, struct ptlrpc_request *req)
237 {
238         struct obd_conn conn;
239         struct ost_body *body;
240         int rc, size[2] = {sizeof(*body)};
241         char *bufs[2] = {NULL, NULL}, *ptr;
242         ENTRY;
243
244         body = lustre_msg_buf(req->rq_reqmsg, 0);
245         conn.oc_id = body->connid;
246         conn.oc_dev = ost->ost_tgt;
247
248         ptr = lustre_msg_buf(req->rq_reqmsg, 1);
249         if (!ptr)
250                 RETURN(-EINVAL);
251
252         req->rq_status = obd_get_info(&conn, req->rq_reqmsg->buflens[1], ptr,
253                                       &(size[1]), (void **)&(bufs[1]));
254
255         rc = lustre_pack_msg(2, size, bufs, &req->rq_replen, &req->rq_repmsg);
256         if (rc)
257                 CERROR("cannot pack reply\n");
258
259         RETURN(rc);
260 }
261
262 static int ost_brw_read(struct ost_obd *obddev, struct ptlrpc_request *req)
263 {
264         struct ptlrpc_bulk_desc **bulk_vec = NULL, *bulk = NULL;
265         struct obd_conn conn;
266         void *tmp1, *tmp2, *end2;
267         struct niobuf *nb, *dst, *res = NULL;
268         struct obd_ioobj *ioo;
269         struct ost_body *body;
270         int rc, cmd, i, j, objcount, niocount, size = sizeof(*body);
271         ENTRY;
272
273         body = lustre_msg_buf(req->rq_reqmsg, 0);
274         tmp1 = lustre_msg_buf(req->rq_reqmsg, 1);
275         tmp2 = lustre_msg_buf(req->rq_reqmsg, 2);
276         end2 = (char *)tmp2 + req->rq_reqmsg->buflens[2];
277         objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
278         niocount = req->rq_reqmsg->buflens[2] / sizeof(*nb);
279         cmd = body->data;
280
281         conn.oc_id = body->connid;
282         conn.oc_dev = req->rq_obd->u.ost.ost_tgt;
283
284         for (i = 0; i < objcount; i++) {
285                 ost_unpack_ioo(&tmp1, &ioo);
286                 if (tmp2 + ioo->ioo_bufcnt > end2) {
287                         LBUG();
288                         rc = -EFAULT;
289                         break;
290                 }
291                 for (j = 0; j < ioo->ioo_bufcnt; j++)
292                         ost_unpack_niobuf(&tmp2, &nb);
293         }
294
295         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
296         if (rc)
297                 RETURN(rc);
298         OBD_ALLOC(res, sizeof(*res) * niocount);
299         if (res == NULL)
300                 RETURN(-ENOMEM);
301
302         /* The unpackers move tmp1 and tmp2, so reset them before using */
303         tmp1 = lustre_msg_buf(req->rq_reqmsg, 1);
304         tmp2 = lustre_msg_buf(req->rq_reqmsg, 2);
305         req->rq_status = obd_preprw(cmd, &conn, objcount,
306                                     tmp1, niocount, tmp2, res);
307
308         if (req->rq_status)
309                 GOTO(out, 0);
310
311         for (i = 0; i < niocount; i++) {
312                 bulk = ptlrpc_prep_bulk(req->rq_connection);
313                 if (bulk == NULL) {
314                         CERROR("cannot alloc bulk desc\n");
315                         GOTO(out, rc = -ENOMEM);
316                 }
317
318                 dst = &(((struct niobuf *)tmp2)[i]);
319                 bulk->b_xid = dst->xid;
320                 bulk->b_buf = (void *)(unsigned long)res[i].addr;
321                 bulk->b_buflen = PAGE_SIZE;
322                 rc = ptlrpc_send_bulk(bulk, OST_BULK_PORTAL);
323                 if (rc)
324                         GOTO(out, rc);
325                 wait_event_interruptible(bulk->b_waitq,
326                                          ptlrpc_check_bulk_sent(bulk));
327
328                 if (bulk->b_flags == PTL_RPC_INTR)
329                         GOTO(out, 0);
330
331                 OBD_FREE(bulk, sizeof(*bulk));
332                 bulk = NULL;
333         }
334
335         /* The unpackers move tmp1 and tmp2, so reset them before using */
336         tmp1 = lustre_msg_buf(req->rq_reqmsg, 1);
337         tmp2 = lustre_msg_buf(req->rq_reqmsg, 2);
338         req->rq_status = obd_commitrw(cmd, &conn, objcount,
339                                       tmp1, niocount, res);
340
341         EXIT;
342  out:
343         if (res != NULL)
344                 OBD_FREE(res, sizeof(*res) * niocount);
345         if (bulk != NULL)
346                 OBD_FREE(bulk, sizeof(*bulk));
347         if (bulk_vec != NULL) {
348                 for (i = 0; i < niocount; i++)
349                         if (bulk_vec[i] != NULL)
350                                 OBD_FREE(bulk_vec[i], sizeof(*bulk));
351                 OBD_FREE(bulk_vec, niocount * sizeof(*bulk_vec));
352         }
353
354         return 0;
355 }
356
357 static int ost_commit_page(struct obd_conn *conn, struct page *page)
358 {
359         struct obd_ioobj obj;
360         struct niobuf buf;
361         int rc;
362         ENTRY;
363
364         memset(&buf, 0, sizeof(buf));
365         memset(&obj, 0, sizeof(obj));
366
367         buf.page = page;
368         obj.ioo_bufcnt = 1;
369
370         rc = obd_commitrw(OBD_BRW_WRITE, conn, 1, &obj, 1, &buf);
371         RETURN(rc);
372 }
373
374 static int ost_brw_write_cb(struct ptlrpc_bulk_desc *bulk, void *data)
375 {
376         int rc;
377
378         ENTRY;
379
380         rc = ost_commit_page(&bulk->b_conn, bulk->b_page);
381         if (rc)
382                 CERROR("ost_commit_page failed: %d\n", rc);
383
384         RETURN(rc);
385 }
386
387 static int ost_brw_write(struct ost_obd *obddev, struct ptlrpc_request *req)
388 {
389         struct obd_conn conn;
390         struct niobuf *nb, *dst;
391         struct obd_ioobj *ioo;
392         struct ost_body *body;
393         int cmd, rc, i, j, objcount, niocount, size[2] = {sizeof(*body)};
394         void *tmp1, *tmp2, *end2, *res;
395         ENTRY;
396
397         body = lustre_msg_buf(req->rq_reqmsg, 0);
398         tmp1 = lustre_msg_buf(req->rq_reqmsg, 1);
399         tmp2 = lustre_msg_buf(req->rq_reqmsg, 2);
400         end2 = (char *)tmp2 + req->rq_reqmsg->buflens[2];
401         objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
402         niocount = req->rq_reqmsg->buflens[2] / sizeof(*nb);
403         cmd = body->data;
404
405         conn.oc_id = body->connid;
406         conn.oc_dev = req->rq_obd->u.ost.ost_tgt;
407
408         for (i = 0; i < objcount; i++) {
409                 ost_unpack_ioo((void *)&tmp1, &ioo);
410                 if (tmp2 + ioo->ioo_bufcnt > end2) {
411                         rc = -EFAULT;
412                         break;
413                 }
414                 for (j = 0; j < ioo->ioo_bufcnt; j++)
415                         ost_unpack_niobuf((void *)&tmp2, &nb);
416         }
417
418         size[1] = niocount * sizeof(*nb);
419         rc = lustre_pack_msg(2, size, NULL, &req->rq_replen, &req->rq_repmsg);
420         if (rc)
421                 RETURN(rc);
422
423         res = lustre_msg_buf(req->rq_repmsg, 1);
424
425         /* The unpackers move tmp1 and tmp2, so reset them before using */
426         tmp1 = lustre_msg_buf(req->rq_reqmsg, 1);
427         tmp2 = lustre_msg_buf(req->rq_reqmsg, 2);
428         req->rq_status = obd_preprw(cmd, &conn, objcount,
429                                     tmp1, niocount, tmp2, res);
430
431         if (req->rq_status)
432                 GOTO(out, 0);
433
434         for (i = 0; i < niocount; i++) {
435                 struct ptlrpc_bulk_desc *bulk;
436                 struct ptlrpc_service *srv = req->rq_obd->u.ost.ost_service;
437
438                 bulk = ptlrpc_prep_bulk(req->rq_connection);
439                 if (bulk == NULL)
440                         GOTO(out, rc = -ENOMEM);
441
442                 spin_lock(&srv->srv_lock);
443                 bulk->b_xid = srv->srv_xid++;
444                 spin_unlock(&srv->srv_lock);
445
446                 dst = &(((struct niobuf *)res)[i]);
447                 dst->xid = HTON__u32(bulk->b_xid);
448
449                 bulk->b_buf = (void *)(unsigned long)dst->addr;
450                 bulk->b_cb = ost_brw_write_cb;
451                 bulk->b_page = dst->page;
452                 memcpy(&(bulk->b_conn), &conn, sizeof(conn));
453                 bulk->b_buflen = PAGE_SIZE;
454                 bulk->b_portal = OSC_BULK_PORTAL;
455                 rc = ptlrpc_register_bulk(bulk);
456                 if (rc)
457                         GOTO(out, rc);
458         }
459
460         EXIT;
461  out:
462         /* FIXME: should we return 'rc' here? */
463         return 0;
464 }
465
466 static int ost_brw(struct ost_obd *obddev, struct ptlrpc_request *req)
467 {
468         struct ost_body *body = lustre_msg_buf(req->rq_reqmsg, 0);
469
470         if (body->data == OBD_BRW_READ)
471                 return ost_brw_read(obddev, req);
472         else
473                 return ost_brw_write(obddev, req);
474 }
475
476 static int ost_handle(struct obd_device *obddev, struct ptlrpc_service *svc,
477                       struct ptlrpc_request *req)
478 {
479         int rc;
480         struct ost_obd *ost = &obddev->u.ost;
481         ENTRY;
482
483         rc = lustre_unpack_msg(req->rq_reqmsg, req->rq_reqlen);
484         if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_HANDLE_UNPACK)) {
485                 CERROR("lustre_mds: Invalid request\n");
486                 GOTO(out, rc);
487         }
488
489         if (req->rq_reqmsg->type != PTL_RPC_REQUEST) {
490                 CERROR("lustre_mds: wrong packet type sent %d\n",
491                        req->rq_reqmsg->type);
492                 GOTO(out, rc = -EINVAL);
493         }
494
495         switch (req->rq_reqmsg->opc) {
496         case OST_CONNECT:
497                 CDEBUG(D_INODE, "connect\n");
498                 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
499                 rc = ost_connect(ost, req);
500                 break;
501         case OST_DISCONNECT:
502                 CDEBUG(D_INODE, "disconnect\n");
503                 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
504                 rc = ost_disconnect(ost, req);
505                 break;
506         case OST_GET_INFO:
507                 CDEBUG(D_INODE, "get_info\n");
508                 OBD_FAIL_RETURN(OBD_FAIL_OST_GET_INFO_NET, 0);
509                 rc = ost_get_info(ost, req);
510                 break;
511         case OST_CREATE:
512                 CDEBUG(D_INODE, "create\n");
513                 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
514                 rc = ost_create(ost, req);
515                 break;
516         case OST_DESTROY:
517                 CDEBUG(D_INODE, "destroy\n");
518                 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
519                 rc = ost_destroy(ost, req);
520                 break;
521         case OST_GETATTR:
522                 CDEBUG(D_INODE, "getattr\n");
523                 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
524                 rc = ost_getattr(ost, req);
525                 break;
526         case OST_SETATTR:
527                 CDEBUG(D_INODE, "setattr\n");
528                 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
529                 rc = ost_setattr(ost, req);
530                 break;
531         case OST_OPEN:
532                 CDEBUG(D_INODE, "setattr\n");
533                 OBD_FAIL_RETURN(OBD_FAIL_OST_OPEN_NET, 0);
534                 rc = ost_open(ost, req);
535                 break;
536         case OST_CLOSE:
537                 CDEBUG(D_INODE, "setattr\n");
538                 OBD_FAIL_RETURN(OBD_FAIL_OST_CLOSE_NET, 0);
539                 rc = ost_close(ost, req);
540                 break;
541         case OST_BRW:
542                 CDEBUG(D_INODE, "brw\n");
543                 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
544                 rc = ost_brw(ost, req);
545                 break;
546         case OST_PUNCH:
547                 CDEBUG(D_INODE, "punch\n");
548                 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
549                 rc = ost_punch(ost, req);
550                 break;
551         default:
552                 req->rq_status = -ENOTSUPP;
553                 rc = ptlrpc_error(svc, req);
554                 RETURN(rc);
555         }
556
557         EXIT;
558 out:
559         //req->rq_status = rc;
560         if (rc) {
561                 CERROR("ost: processing error %d\n", rc);
562                 ptlrpc_error(svc, req);
563         } else {
564                 CDEBUG(D_INODE, "sending reply\n");
565                 ptlrpc_reply(svc, req);
566         }
567
568         return 0;
569 }
570
571 /* mount the file system (secretly) */
572 static int ost_setup(struct obd_device *obddev, obd_count len, void *buf)
573 {
574         struct obd_ioctl_data* data = buf;
575         struct ost_obd *ost = &obddev->u.ost;
576         struct obd_device *tgt;
577         int err;
578         ENTRY;
579
580         if (data->ioc_dev < 0 || data->ioc_dev > MAX_OBD_DEVICES)
581                 RETURN(-ENODEV);
582
583         MOD_INC_USE_COUNT;
584         tgt = &obd_dev[data->ioc_dev];
585         ost->ost_tgt = tgt;
586         if (!(tgt->obd_flags & OBD_ATTACHED) ||
587             !(tgt->obd_flags & OBD_SET_UP)) {
588                 CERROR("device not attached or not set up (%d)\n",
589                        data->ioc_dev);
590                 GOTO(error_dec, err = -EINVAL);
591         }
592
593         ost->ost_conn.oc_dev = tgt;
594         err = obd_connect(&ost->ost_conn);
595         if (err) {
596                 CERROR("fail to connect to device %d\n", data->ioc_dev);
597                 GOTO(error_dec, err = -EINVAL);
598         }
599
600         ost->ost_service = ptlrpc_init_svc(128 * 1024,
601                                            OST_REQUEST_PORTAL, OSC_REPLY_PORTAL,
602                                            "self", ost_handle);
603         if (!ost->ost_service) {
604                 CERROR("failed to start service\n");
605                 GOTO(error_disc, err = -EINVAL);
606         }
607
608         err = ptlrpc_start_thread(obddev, ost->ost_service, "lustre_ost");
609         if (err)
610                 GOTO(error_disc, err = -EINVAL);
611
612         RETURN(0);
613
614 error_disc:
615         obd_disconnect(&ost->ost_conn);
616 error_dec:
617         MOD_DEC_USE_COUNT;
618         RETURN(err);
619 }
620
621 static int ost_cleanup(struct obd_device * obddev)
622 {
623         struct ost_obd *ost = &obddev->u.ost;
624         int err;
625
626         ENTRY;
627
628         if ( !list_empty(&obddev->obd_gen_clients) ) {
629                 CERROR("still has clients!\n");
630                 RETURN(-EBUSY);
631         }
632
633         ptlrpc_stop_thread(ost->ost_service);
634         rpc_unregister_service(ost->ost_service);
635
636         if (!list_empty(&ost->ost_service->srv_reqs)) {
637                 // XXX reply with errors and clean up
638                 CERROR("Request list not empty!\n");
639         }
640         OBD_FREE(ost->ost_service, sizeof(*ost->ost_service));
641
642         err = obd_disconnect(&ost->ost_conn);
643         if (err) {
644                 CERROR("lustre ost: fail to disconnect device\n");
645                 RETURN(-EINVAL);
646         }
647
648         MOD_DEC_USE_COUNT;
649         RETURN(0);
650 }
651
652 /* use obd ops to offer management infrastructure */
653 static struct obd_ops ost_obd_ops = {
654         o_setup:       ost_setup,
655         o_cleanup:     ost_cleanup,
656 };
657
658 static int __init ost_init(void)
659 {
660         obd_register_type(&ost_obd_ops, LUSTRE_OST_NAME);
661         return 0;
662 }
663
664 static void __exit ost_exit(void)
665 {
666         obd_unregister_type(LUSTRE_OST_NAME);
667 }
668
669 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
670 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
671 MODULE_LICENSE("GPL");
672
673 module_init(ost_init);
674 module_exit(ost_exit);