Whamcloud - gitweb
- see message on previous commit.
[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_FL_INTR)
329                         GOTO(out, 0);
330
331                 ptlrpc_free_bulk(bulk);
332         }
333         bulk = NULL;
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                 ptlrpc_free_bulk(bulk);
347         if (bulk_vec != NULL) {
348                 for (i = 0; i < niocount; i++)
349                         if (bulk_vec[i] != NULL)
350                                 ptlrpc_free_bulk(bulk_vec[i]);
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, *res;
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;
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++, res++) {
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                 res->xid = HTON__u32(bulk->b_xid);
447
448                 bulk->b_buf = (void *)(unsigned long)res->addr;
449                 bulk->b_cb = ost_brw_write_cb;
450                 bulk->b_page = res->page;
451                 memcpy(&(bulk->b_conn), &conn, sizeof(conn));
452                 bulk->b_buflen = PAGE_SIZE;
453                 bulk->b_portal = OSC_BULK_PORTAL;
454                 rc = ptlrpc_register_bulk(bulk);
455                 if (rc)
456                         GOTO(out, rc);
457         }
458
459         EXIT;
460  out:
461         /* FIXME: should we return 'rc' here? */
462         return 0;
463 }
464
465 static int ost_brw(struct ost_obd *obddev, struct ptlrpc_request *req)
466 {
467         struct ost_body *body = lustre_msg_buf(req->rq_reqmsg, 0);
468
469         if (body->data == OBD_BRW_READ)
470                 return ost_brw_read(obddev, req);
471         else
472                 return ost_brw_write(obddev, req);
473 }
474
475 static int ost_handle(struct obd_device *obddev, struct ptlrpc_service *svc,
476                       struct ptlrpc_request *req)
477 {
478         int rc;
479         struct ost_obd *ost = &obddev->u.ost;
480         ENTRY;
481
482         rc = lustre_unpack_msg(req->rq_reqmsg, req->rq_reqlen);
483         if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_HANDLE_UNPACK)) {
484                 CERROR("lustre_mds: Invalid request\n");
485                 GOTO(out, rc);
486         }
487
488         if (req->rq_reqmsg->type != PTL_RPC_MSG_REQUEST) {
489                 CERROR("lustre_mds: wrong packet type sent %d\n",
490                        req->rq_reqmsg->type);
491                 GOTO(out, rc = -EINVAL);
492         }
493
494         switch (req->rq_reqmsg->opc) {
495         case OST_CONNECT:
496                 CDEBUG(D_INODE, "connect\n");
497                 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
498                 rc = ost_connect(ost, req);
499                 break;
500         case OST_DISCONNECT:
501                 CDEBUG(D_INODE, "disconnect\n");
502                 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
503                 rc = ost_disconnect(ost, req);
504                 break;
505         case OST_GET_INFO:
506                 CDEBUG(D_INODE, "get_info\n");
507                 OBD_FAIL_RETURN(OBD_FAIL_OST_GET_INFO_NET, 0);
508                 rc = ost_get_info(ost, req);
509                 break;
510         case OST_CREATE:
511                 CDEBUG(D_INODE, "create\n");
512                 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
513                 rc = ost_create(ost, req);
514                 break;
515         case OST_DESTROY:
516                 CDEBUG(D_INODE, "destroy\n");
517                 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
518                 rc = ost_destroy(ost, req);
519                 break;
520         case OST_GETATTR:
521                 CDEBUG(D_INODE, "getattr\n");
522                 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
523                 rc = ost_getattr(ost, req);
524                 break;
525         case OST_SETATTR:
526                 CDEBUG(D_INODE, "setattr\n");
527                 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
528                 rc = ost_setattr(ost, req);
529                 break;
530         case OST_OPEN:
531                 CDEBUG(D_INODE, "setattr\n");
532                 OBD_FAIL_RETURN(OBD_FAIL_OST_OPEN_NET, 0);
533                 rc = ost_open(ost, req);
534                 break;
535         case OST_CLOSE:
536                 CDEBUG(D_INODE, "setattr\n");
537                 OBD_FAIL_RETURN(OBD_FAIL_OST_CLOSE_NET, 0);
538                 rc = ost_close(ost, req);
539                 break;
540         case OST_BRW:
541                 CDEBUG(D_INODE, "brw\n");
542                 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
543                 rc = ost_brw(ost, req);
544                 break;
545         case OST_PUNCH:
546                 CDEBUG(D_INODE, "punch\n");
547                 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
548                 rc = ost_punch(ost, req);
549                 break;
550         default:
551                 req->rq_status = -ENOTSUPP;
552                 rc = ptlrpc_error(svc, req);
553                 RETURN(rc);
554         }
555
556         EXIT;
557 out:
558         //req->rq_status = rc;
559         if (rc) {
560                 CERROR("ost: processing error %d\n", rc);
561                 ptlrpc_error(svc, req);
562         } else {
563                 CDEBUG(D_INODE, "sending reply\n");
564                 ptlrpc_reply(svc, req);
565         }
566
567         return 0;
568 }
569
570 /* mount the file system (secretly) */
571 static int ost_setup(struct obd_device *obddev, obd_count len, void *buf)
572 {
573         struct obd_ioctl_data* data = buf;
574         struct ost_obd *ost = &obddev->u.ost;
575         struct obd_device *tgt;
576         int err;
577         ENTRY;
578
579         if (data->ioc_dev < 0 || data->ioc_dev > MAX_OBD_DEVICES)
580                 RETURN(-ENODEV);
581
582         MOD_INC_USE_COUNT;
583         tgt = &obd_dev[data->ioc_dev];
584         ost->ost_tgt = tgt;
585         if (!(tgt->obd_flags & OBD_ATTACHED) ||
586             !(tgt->obd_flags & OBD_SET_UP)) {
587                 CERROR("device not attached or not set up (%d)\n",
588                        data->ioc_dev);
589                 GOTO(error_dec, err = -EINVAL);
590         }
591
592         ost->ost_conn.oc_dev = tgt;
593         err = obd_connect(&ost->ost_conn);
594         if (err) {
595                 CERROR("fail to connect to device %d\n", data->ioc_dev);
596                 GOTO(error_dec, err = -EINVAL);
597         }
598
599         ost->ost_service = ptlrpc_init_svc(128 * 1024,
600                                            OST_REQUEST_PORTAL, OSC_REPLY_PORTAL,
601                                            "self", ost_handle);
602         if (!ost->ost_service) {
603                 CERROR("failed to start service\n");
604                 GOTO(error_disc, err = -EINVAL);
605         }
606
607         err = ptlrpc_start_thread(obddev, ost->ost_service, "lustre_ost");
608         if (err)
609                 GOTO(error_disc, err = -EINVAL);
610
611         RETURN(0);
612
613 error_disc:
614         obd_disconnect(&ost->ost_conn);
615 error_dec:
616         MOD_DEC_USE_COUNT;
617         RETURN(err);
618 }
619
620 static int ost_cleanup(struct obd_device * obddev)
621 {
622         struct ost_obd *ost = &obddev->u.ost;
623         int err;
624
625         ENTRY;
626
627         if ( !list_empty(&obddev->obd_gen_clients) ) {
628                 CERROR("still has clients!\n");
629                 RETURN(-EBUSY);
630         }
631
632         ptlrpc_stop_thread(ost->ost_service);
633         rpc_unregister_service(ost->ost_service);
634
635         if (!list_empty(&ost->ost_service->srv_reqs)) {
636                 // XXX reply with errors and clean up
637                 CERROR("Request list not empty!\n");
638         }
639         OBD_FREE(ost->ost_service, sizeof(*ost->ost_service));
640
641         err = obd_disconnect(&ost->ost_conn);
642         if (err) {
643                 CERROR("lustre ost: fail to disconnect device\n");
644                 RETURN(-EINVAL);
645         }
646
647         MOD_DEC_USE_COUNT;
648         RETURN(0);
649 }
650
651 /* use obd ops to offer management infrastructure */
652 static struct obd_ops ost_obd_ops = {
653         o_setup:       ost_setup,
654         o_cleanup:     ost_cleanup,
655 };
656
657 static int __init ost_init(void)
658 {
659         obd_register_type(&ost_obd_ops, LUSTRE_OST_NAME);
660         return 0;
661 }
662
663 static void __exit ost_exit(void)
664 {
665         obd_unregister_type(LUSTRE_OST_NAME);
666 }
667
668 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
669 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
670 MODULE_LICENSE("GPL");
671
672 module_init(ost_init);
673 module_exit(ost_exit);