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