Whamcloud - gitweb
b=1644
[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-2003 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 #include <linux/lustre_dlm.h>
40 #include <linux/lustre_export.h>
41 #include <linux/init.h>
42 #include <linux/lprocfs_status.h>
43 #include <linux/lustre_commit_confd.h>
44 #include <portals/list.h>
45
46 void oti_init(struct obd_trans_info *oti, struct ptlrpc_request *req)
47 {
48         if (oti == NULL)
49                 return;
50         memset(oti, 0, sizeof *oti);
51
52         if (req->rq_repmsg && req->rq_reqmsg != 0)
53                 oti->oti_transno = req->rq_repmsg->transno;
54 }
55
56 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
57 {
58         struct oti_req_ack_lock *ack_lock;
59         int i;
60
61         if (oti == NULL)
62                 return;
63
64         if (req->rq_repmsg)
65                 req->rq_repmsg->transno = oti->oti_transno;
66
67         /* XXX 4 == entries in oti_ack_locks??? */
68         for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
69                 if (!ack_lock->mode)
70                         break;
71                 memcpy(&req->rq_ack_locks[i].lock, &ack_lock->lock,
72                        sizeof(req->rq_ack_locks[i].lock));
73                 req->rq_ack_locks[i].mode = ack_lock->mode;
74         }
75 }
76
77 static int ost_destroy(struct ptlrpc_request *req, struct obd_trans_info *oti)
78 {
79         struct lustre_handle *conn = &req->rq_reqmsg->handle;
80         struct ost_body *body;
81         int rc, size = sizeof(*body);
82         ENTRY;
83
84         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
85         if (body == NULL)
86                 RETURN(-EFAULT);
87
88         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
89         if (rc)
90                 RETURN(rc);
91
92         if (body->oa.o_valid & OBD_MD_FLCOOKIE)
93                 oti->oti_logcookies = obdo_logcookie(&body->oa);
94         req->rq_status = obd_destroy(conn, &body->oa, NULL, oti);
95         RETURN(0);
96 }
97
98 static int ost_getattr(struct ptlrpc_request *req)
99 {
100         struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
101         struct ost_body *body, *repbody;
102         int rc, size = sizeof(*body);
103         ENTRY;
104
105         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
106         if (body == NULL)
107                 RETURN(-EFAULT);
108
109         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
110         if (rc)
111                 RETURN(rc);
112
113         repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
114         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
115         req->rq_status = obd_getattr(conn, &repbody->oa, NULL);
116         RETURN(0);
117 }
118
119 static int ost_statfs(struct ptlrpc_request *req)
120 {
121         struct obd_statfs *osfs;
122         int rc, size = sizeof(*osfs);
123         ENTRY;
124
125         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
126         if (rc)
127                 RETURN(rc);
128
129         osfs = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*osfs));
130
131         req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs, jiffies-HZ);
132         if (req->rq_status != 0)
133                 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
134
135         RETURN(0);
136 }
137
138 static int ost_syncfs(struct ptlrpc_request *req)
139 {
140         struct obd_statfs *osfs;
141         int rc, size = sizeof(*osfs);
142         ENTRY;
143
144         rc = lustre_pack_msg(0, &size, NULL, &req->rq_replen, &req->rq_repmsg);
145         if (rc)
146                 RETURN(rc);
147
148         rc = obd_syncfs(req->rq_export);
149         if (rc) {
150                 CERROR("ost: syncfs failed: rc %d\n", rc);
151                 req->rq_status = rc;
152                 RETURN(rc);
153         }
154
155         RETURN(0);
156 }
157
158 static int ost_open(struct ptlrpc_request *req, struct obd_trans_info *oti)
159 {
160         struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
161         struct ost_body *body, *repbody;
162         int rc, size = sizeof(*repbody);
163         ENTRY;
164
165         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
166         if (body == NULL)
167                 RETURN(-EFAULT);
168
169         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
170         if (rc)
171                 RETURN(rc);
172
173         repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
174         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
175         req->rq_status = obd_open(conn, &repbody->oa, NULL, oti, NULL);
176         RETURN(0);
177 }
178
179 static int ost_close(struct ptlrpc_request *req, struct obd_trans_info *oti)
180 {
181         struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
182         struct ost_body *body, *repbody;
183         int rc, size = sizeof(*repbody);
184         ENTRY;
185
186         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
187         if (body == NULL)
188                 RETURN(-EFAULT);
189
190         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
191         if (rc)
192                 RETURN(rc);
193
194         repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
195         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
196         req->rq_status = obd_close(conn, &repbody->oa, NULL, oti);
197         RETURN(0);
198 }
199
200 static int ost_create(struct ptlrpc_request *req, struct obd_trans_info *oti)
201 {
202         struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
203         struct ost_body *body, *repbody;
204         int rc, size = sizeof(*repbody);
205         ENTRY;
206
207         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
208         if (body == NULL)
209                 RETURN(-EFAULT);
210
211         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
212         if (rc)
213                 RETURN(rc);
214
215         repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
216         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
217         oti->oti_logcookies = obdo_logcookie(&repbody->oa);
218         req->rq_status = obd_create(conn, &repbody->oa, NULL, oti);
219         //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
220         RETURN(0);
221 }
222
223 static int ost_punch(struct ptlrpc_request *req, struct obd_trans_info *oti)
224 {
225         struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
226         struct ost_body *body, *repbody;
227         int rc, size = sizeof(*repbody);
228         ENTRY;
229
230         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
231         if (body == NULL)
232                 RETURN(-EFAULT);
233
234         if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
235             (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
236                 RETURN(-EINVAL);
237
238         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
239         if (rc)
240                 RETURN(rc);
241
242         repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
243         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
244         req->rq_status = obd_punch(conn, &repbody->oa, NULL, repbody->oa.o_size,
245                                    repbody->oa.o_blocks, oti);
246         RETURN(0);
247 }
248
249 static int ost_setattr(struct ptlrpc_request *req, struct obd_trans_info *oti)
250 {
251         struct lustre_handle *conn = &req->rq_reqmsg->handle;
252         struct ost_body *body, *repbody;
253         int rc, size = sizeof(*repbody);
254         ENTRY;
255
256         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
257         if (body == NULL)
258                 RETURN(-EFAULT);
259
260         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
261         if (rc)
262                 RETURN(rc);
263
264         repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
265         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
266
267         req->rq_status = obd_setattr(conn, &repbody->oa, NULL, oti);
268         RETURN(0);
269 }
270
271 static int ost_bulk_timeout(void *data)
272 {
273         ENTRY;
274         /* We don't fail the connection here, because having the export
275          * killed makes the (vital) call to commitrw very sad.
276          */
277         RETURN(1);
278 }
279
280 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
281                                 struct niobuf_remote *rnb, int nrnb,
282                                 struct niobuf_remote **pp_rnbp)
283 {
284         /* Copy a remote niobuf, splitting it into page-sized chunks
285          * and setting ioo[i].ioo_bufcnt accordingly */
286         struct niobuf_remote *pp_rnb;
287         int   i;
288         int   j;
289         int   page;
290         int   rnbidx = 0;
291         int   npages = 0;
292
293         /* first count and check the number of pages required */
294         for (i = 0; i < nioo; i++)
295                 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
296                         obd_off offset = rnb[rnbidx].offset;
297                         obd_off p0 = offset >> PAGE_SHIFT;
298                         obd_off pn = (offset + rnb[rnbidx].len - 1)>>PAGE_SHIFT;
299
300                         LASSERT(rnbidx < nrnb);
301
302                         npages += (pn + 1 - p0);
303
304                         if (rnb[rnbidx].len == 0) {
305                                 CERROR("zero len BRW: obj %d objid "LPX64
306                                        " buf %u\n", i, ioo[i].ioo_id, j);
307                                 return -EINVAL;
308                         }
309                         if (j > 0 &&
310                             rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
311                                 CERROR("unordered BRW: obj %d objid "LPX64
312                                        " buf %u offset "LPX64" <= "LPX64"\n",
313                                        i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
314                                        rnb[rnbidx].offset);
315                                 return -EINVAL;
316                         }
317                 }
318
319         LASSERT(rnbidx == nrnb);
320
321         if (npages == nrnb) {       /* all niobufs are for single pages */
322                 *pp_rnbp = rnb;
323                 return npages;
324         }
325
326         OBD_ALLOC(pp_rnb, sizeof(*pp_rnb) * npages);
327         if (pp_rnb == NULL)
328                 return -ENOMEM;
329
330         /* now do the actual split */
331         page = rnbidx = 0;
332         for (i = 0; i < nioo; i++) {
333                 int  obj_pages = 0;
334
335                 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
336                         obd_off off = rnb[rnbidx].offset;
337                         int     nob = rnb[rnbidx].len;
338
339                         LASSERT(rnbidx < nrnb);
340                         do {
341                                 obd_off  poff = off & (PAGE_SIZE - 1);
342                                 int      pnob = (poff + nob > PAGE_SIZE) ?
343                                                 PAGE_SIZE - poff : nob;
344
345                                 LASSERT(page < npages);
346                                 pp_rnb[page].len = pnob;
347                                 pp_rnb[page].offset = off;
348                                 pp_rnb[page].flags = rnb->flags;
349
350                                 CDEBUG(D_PAGE, "   obj %d id "LPX64
351                                        "page %d(%d) "LPX64" for %d\n",
352                                        i, ioo[i].ioo_id, obj_pages, page,
353                                        pp_rnb[page].offset, pp_rnb[page].len);
354                                 page++;
355                                 obj_pages++;
356
357                                 off += pnob;
358                                 nob -= pnob;
359                         } while (nob > 0);
360                         LASSERT(nob == 0);
361                 }
362                 ioo[i].ioo_bufcnt = obj_pages;
363         }
364         LASSERT(page == npages);
365
366         *pp_rnbp = pp_rnb;
367         return npages;
368 }
369
370 static void free_per_page_niobufs (int npages, struct niobuf_remote *pp_rnb,
371                                    struct niobuf_remote *rnb)
372 {
373         if (pp_rnb == rnb)                      /* didn't allocate above */
374                 return;
375
376         OBD_FREE(pp_rnb, sizeof(*pp_rnb) * npages);
377 }
378
379 #if CHECKSUM_BULK
380 __u64 ost_checksum_bulk (struct ptlrpc_bulk_desc *desc)
381 {
382         __u64             cksum = 0;
383         struct ptlrpc_bulk_page *bp;
384
385         list_for_each_entry(bp, &desc->bd_page_list, bp_link) {
386                 ost_checksum(&cksum, kmap(bp->bp_page) + bp->bp_pageoffset,
387                              bp->bp_buflen);
388                 kunmap(bp->bp_page);
389         }
390 }
391 #endif
392
393 static int ost_brw_read(struct ptlrpc_request *req)
394 {
395         struct ptlrpc_bulk_desc *desc;
396         struct niobuf_remote    *remote_nb;
397         struct niobuf_remote    *pp_rnb;
398         struct niobuf_local     *local_nb;
399         struct obd_ioobj        *ioo;
400         struct ost_body         *body, *repbody;
401         struct l_wait_info       lwi;
402         struct obd_trans_info    oti = { 0 };
403         int                      size[1] = { sizeof(*body) };
404         int                      comms_error = 0;
405         int                      niocount;
406         int                      npages;
407         int                      nob = 0;
408         int                      rc;
409         int                      i;
410         ENTRY;
411
412         if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
413                 GOTO(out, rc = -EIO);
414
415         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
416         if (body == NULL) {
417                 CERROR("Missing/short ost_body\n");
418                 GOTO(out, rc = -EFAULT);
419         }
420
421         /* BUG 974: when we send back cache grants, don't clear this flag */
422         body->oa.o_valid &= ~OBD_MD_FLRDEV;
423
424         ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
425         if (ioo == NULL) {
426                 CERROR("Missing/short ioobj\n");
427                 GOTO(out, rc = -EFAULT);
428         }
429
430         niocount = ioo->ioo_bufcnt;
431         remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
432                                        lustre_swab_niobuf_remote);
433         if (remote_nb == NULL) {
434                 CERROR("Missing/short niobuf\n");
435                 GOTO(out, rc = -EFAULT);
436         }
437         if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
438                 for (i = 1; i < niocount; i++)
439                         lustre_swab_niobuf_remote (&remote_nb[i]);
440         }
441
442         size[0] = sizeof(*body);
443         rc = lustre_pack_msg(1, size, NULL, &req->rq_replen, &req->rq_repmsg);
444         if (rc)
445                 GOTO(out, rc);
446
447         /* FIXME all niobuf splitting should be done in obdfilter if needed */
448         /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
449         npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
450         if (npages < 0)
451                 GOTO(out, rc = npages);
452
453         OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
454         if (local_nb == NULL)
455                 GOTO(out_pp_rnb, rc = -ENOMEM);
456
457         desc = ptlrpc_prep_bulk_exp(req, BULK_PUT_SOURCE, OST_BULK_PORTAL);
458         if (desc == NULL)
459                 GOTO(out_local, rc = -ENOMEM);
460
461         rc = obd_preprw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
462                         ioo, npages, pp_rnb, local_nb, &oti);
463         if (rc != 0)
464                 GOTO(out_bulk, rc);
465
466         nob = 0;
467         for (i = 0; i < npages; i++) {
468                 int page_rc = local_nb[i].rc;
469
470                 if (page_rc < 0) {              /* error */
471                         rc = page_rc;
472                         break;
473                 }
474
475                 LASSERT(page_rc <= pp_rnb[i].len);
476                 nob += page_rc;
477                 if (page_rc != 0) {             /* some data! */
478                         LASSERT (local_nb[i].page != NULL);
479                         rc = ptlrpc_prep_bulk_page(desc, local_nb[i].page,
480                                                    pp_rnb[i].offset& ~PAGE_MASK,
481                                                    page_rc);
482                         if (rc != 0)
483                                 break;
484                 }
485
486                 if (page_rc != pp_rnb[i].len) { /* short read */
487                         /* All subsequent pages should be 0 */
488                         while(++i < npages)
489                                 LASSERT(local_nb[i].rc == 0);
490                         break;
491                 }
492         }
493
494         if (rc == 0) {
495                 rc = ptlrpc_bulk_put(desc);
496                 if (rc == 0) {
497                         lwi = LWI_TIMEOUT(obd_timeout * HZ, ost_bulk_timeout,
498                                           desc);
499                         rc = l_wait_event(desc->bd_waitq,
500                                           ptlrpc_bulk_complete(desc), &lwi);
501                         if (rc) {
502                                 LASSERT(rc == -ETIMEDOUT);
503                                 CERROR ("timeout waiting for bulk PUT\n");
504                                 ptlrpc_abort_bulk(desc);
505                         }
506                 } else {
507                         CERROR("ptlrpc_bulk_put failed RC: %d\n", rc);
508                 }
509                 comms_error = rc != 0;
510         }
511
512         /* Must commit after prep above in all cases */
513         rc = obd_commitrw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
514                           ioo, npages, local_nb, &oti);
515
516         repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
517         memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
518
519 #if CHECKSUM_BULK
520         if (rc == 0) {
521                 repbody->oa.o_rdev = ost_checksum_bulk(desc);
522                 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
523         }
524 #endif
525
526  out_bulk:
527         ptlrpc_free_bulk(desc);
528  out_local:
529         OBD_FREE(local_nb, sizeof(*local_nb) * npages);
530  out_pp_rnb:
531         free_per_page_niobufs(npages, pp_rnb, remote_nb);
532  out:
533         LASSERT(rc <= 0);
534         if (rc == 0) {
535                 req->rq_status = nob;
536                 ptlrpc_reply(req);
537         } else if (!comms_error) {
538                 /* only reply if comms OK */
539                 req->rq_status = rc;
540                 ptlrpc_error(req);
541         } else {
542                 if (req->rq_repmsg != NULL) {
543                         /* reply out callback would free */
544                         OBD_FREE(req->rq_repmsg, req->rq_replen);
545                 }
546                 CERROR("bulk IO comms error: evicting %s@%s nid "LPU64"\n",
547                        req->rq_export->exp_client_uuid.uuid,
548                        req->rq_connection->c_remote_uuid.uuid,
549                        req->rq_connection->c_peer.peer_nid);
550                 ptlrpc_fail_export(req->rq_export);
551         }
552
553         RETURN(rc);
554 }
555
556 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
557 {
558         struct ptlrpc_bulk_desc *desc;
559         struct niobuf_remote    *remote_nb;
560         struct niobuf_remote    *pp_rnb;
561         struct niobuf_local     *local_nb;
562         struct obd_ioobj        *ioo;
563         struct ost_body         *body, *repbody;
564         struct l_wait_info       lwi;
565         __u32                   *rcs;
566         int                      size[2] = { sizeof(*body) };
567         int                      objcount, niocount, npages;
568         int                      comms_error = 0;
569         int                      rc, rc2, swab, i, j;
570         ENTRY;
571
572         if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
573                 GOTO(out, rc = -EIO);
574
575         /* pause before transaction has been started */
576         OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
577                          obd_timeout +1);
578
579         swab = lustre_msg_swabbed(req->rq_reqmsg);
580         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
581         if (body == NULL) {
582                 CERROR("Missing/short ost_body\n");
583                 GOTO(out, rc = -EFAULT);
584         }
585
586         /* BUG 974: when we send back cache grants, don't clear this flag */
587         body->oa.o_valid &= ~OBD_MD_FLRDEV;
588
589         LASSERT_REQSWAB(req, 1);
590         objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
591         if (objcount == 0) {
592                 CERROR("Missing/short ioobj\n");
593                 GOTO(out, rc = -EFAULT);
594         }
595         ioo = lustre_msg_buf (req->rq_reqmsg, 1, objcount * sizeof(*ioo));
596         LASSERT (ioo != NULL);
597         for (niocount = i = 0; i < objcount; i++) {
598                 if (swab)
599                         lustre_swab_obd_ioobj (&ioo[i]);
600                 if (ioo[i].ioo_bufcnt == 0) {
601                         CERROR("ioo[%d] has zero bufcnt\n", i);
602                         GOTO(out, rc = -EFAULT);
603                 }
604                 niocount += ioo[i].ioo_bufcnt;
605         }
606
607         remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
608                                        lustre_swab_niobuf_remote);
609         if (remote_nb == NULL) {
610                 CERROR("Missing/short niobuf\n");
611                 GOTO(out, rc = -EFAULT);
612         }
613         if (swab) {                             /* swab the remaining niobufs */
614                 for (i = 1; i < niocount; i++)
615                         lustre_swab_niobuf_remote (&remote_nb[i]);
616         }
617
618         size[1] = niocount * sizeof(*rcs);
619         rc = lustre_pack_msg(2, size, NULL, &req->rq_replen,
620                              &req->rq_repmsg);
621         if (rc != 0)
622                 GOTO(out, rc);
623         rcs = lustre_msg_buf(req->rq_repmsg, 1, niocount * sizeof(*rcs));
624
625         /* FIXME all niobuf splitting should be done in obdfilter if needed */
626         /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
627         npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
628         if (npages < 0)
629                 GOTO(out, rc = npages);
630
631         OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
632         if (local_nb == NULL)
633                 GOTO(out_pp_rnb, rc = -ENOMEM);
634
635         desc = ptlrpc_prep_bulk_exp(req, BULK_GET_SINK, OST_BULK_PORTAL);
636         if (desc == NULL)
637                 GOTO(out_local, rc = -ENOMEM);
638
639         rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, &body->oa, objcount,
640                         ioo, npages, pp_rnb, local_nb, oti);
641         if (rc != 0)
642                 GOTO(out_bulk, rc);
643
644         /* NB Having prepped, we must commit... */
645
646         for (i = 0; i < npages; i++) {
647                 rc = ptlrpc_prep_bulk_page(desc, local_nb[i].page,
648                                            pp_rnb[i].offset & (PAGE_SIZE - 1),
649                                            pp_rnb[i].len);
650                 if (rc != 0)
651                         break;
652         }
653
654         if (rc == 0) {
655                 rc = ptlrpc_bulk_get(desc);
656                 if (rc == 0) {
657                         lwi = LWI_TIMEOUT(obd_timeout * HZ, ost_bulk_timeout,
658                                           desc);
659                         rc = l_wait_event(desc->bd_waitq,
660                                           ptlrpc_bulk_complete(desc), &lwi);
661                         if (rc) {
662                                 LASSERT(rc == -ETIMEDOUT);
663                                 CERROR("timeout waiting for bulk GET\n");
664                                 ptlrpc_abort_bulk(desc);
665                         }
666                 } else {
667                         CERROR("ptlrpc_bulk_get failed RC: %d\n", rc);
668                 }
669                 comms_error = rc != 0;
670         }
671
672         repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
673         memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
674
675 #if CHECKSUM_BULK
676         if (rc == 0 && (body->oa.o_valid & OBD_MD_FLCKSUM) != 0) {
677                 static int cksum_counter;
678                 __u64 client_cksum = body->oa.o_rdev;
679                 __u64 cksum = ost_checksum_bulk(desc);
680
681                 if (client_cksum != cksum) {
682                         CERROR("Bad checksum: client "LPX64", server "LPX64
683                                ", client NID "LPX64"\n", client_cksum, cksum,
684                                req->rq_connection->c_peer.peer_nid);
685                         cksum_counter = 1;
686                         repbody->oa.o_rdev = cksum;
687                 } else {
688                         cksum_counter++;
689                         if ((cksum_counter & (-cksum_counter)) == cksum_counter)
690                                 CERROR("Checksum %d from "LPX64": "LPX64" OK\n",
691                                         cksum_counter,
692                                         req->rq_connection->c_peer.peer_nid,
693                                         cksum);
694                 }
695         }
696 #endif
697         /* Must commit after prep above in all cases */
698         rc2 = obd_commitrw(OBD_BRW_WRITE, req->rq_export, &repbody->oa,
699                            objcount, ioo, npages, local_nb, oti);
700
701         if (rc == 0) {
702                 /* set per-requested niobuf return codes */
703                 for (i = j = 0; i < niocount; i++) {
704                         int nob = remote_nb[i].len;
705
706                         rcs[i] = 0;
707                         do {
708                                 LASSERT(j < npages);
709                                 if (local_nb[j].rc < 0)
710                                         rcs[i] = local_nb[j].rc;
711                                 nob -= pp_rnb[j].len;
712                                 j++;
713                         } while (nob > 0);
714                         LASSERT(nob == 0);
715                 }
716                 LASSERT(j == npages);
717         }
718         if (rc == 0)
719                 rc = rc2;
720
721  out_bulk:
722         ptlrpc_free_bulk(desc);
723  out_local:
724         OBD_FREE(local_nb, sizeof(*local_nb) * npages);
725  out_pp_rnb:
726         free_per_page_niobufs(npages, pp_rnb, remote_nb);
727  out:
728         if (rc == 0) {
729                 oti_to_request(oti, req);
730                 rc = ptlrpc_reply(req);
731         } else if (!comms_error) {
732                 /* Only reply if there was no comms problem with bulk */
733                 req->rq_status = rc;
734                 ptlrpc_error(req);
735         } else {
736                 if (req->rq_repmsg != NULL) {
737                         /* reply out callback would free */
738                         OBD_FREE (req->rq_repmsg, req->rq_replen);
739                 }
740                 CERROR("bulk IO comms error: evicting %s@%s nid "LPU64"\n",
741                        req->rq_export->exp_client_uuid.uuid,
742                        req->rq_connection->c_remote_uuid.uuid,
743                        req->rq_connection->c_peer.peer_nid);
744                 ptlrpc_fail_export(req->rq_export);
745         }
746         RETURN(rc);
747 }
748
749 static int ost_san_brw(struct ptlrpc_request *req, int cmd)
750 {
751         struct niobuf_remote *remote_nb, *res_nb;
752         struct obd_ioobj *ioo;
753         struct ost_body *body, *repbody;
754         int rc, i, j, objcount, niocount, size[2] = {sizeof(*body)};
755         int n;
756         int swab;
757         ENTRY;
758
759         /* XXX not set to use latest protocol */
760
761         swab = lustre_msg_swabbed(req->rq_reqmsg);
762         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
763         if (body == NULL) {
764                 CERROR("Missing/short ost_body\n");
765                 GOTO(out, rc = -EFAULT);
766         }
767
768         ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
769         if (ioo == NULL) {
770                 CERROR("Missing/short ioobj\n");
771                 GOTO(out, rc = -EFAULT);
772         }
773         objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
774         niocount = ioo[0].ioo_bufcnt;
775         for (i = 1; i < objcount; i++) {
776                 if (swab)
777                         lustre_swab_obd_ioobj (&ioo[i]);
778                 niocount += ioo[i].ioo_bufcnt;
779         }
780
781         remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
782                                        lustre_swab_niobuf_remote);
783         if (remote_nb == NULL) {
784                 CERROR("Missing/short niobuf\n");
785                 GOTO(out, rc = -EFAULT);
786         }
787         if (swab) {                             /* swab the remaining niobufs */
788                 for (i = 1; i < niocount; i++)
789                         lustre_swab_niobuf_remote (&remote_nb[i]);
790         }
791
792         for (i = n = 0; i < objcount; i++) {
793                 for (j = 0; j < ioo[i].ioo_bufcnt; j++, n++) {
794                         if (remote_nb[n].len == 0) {
795                                 CERROR("zero len BRW: objid "LPX64" buf %u\n",
796                                        ioo[i].ioo_id, j);
797                                 GOTO(out, rc = -EINVAL);
798                         }
799                         if (j && remote_nb[n].offset <= remote_nb[n-1].offset) {
800                                 CERROR("unordered BRW: objid "LPX64
801                                        " buf %u offset "LPX64" <= "LPX64"\n",
802                                        ioo[i].ioo_id, j, remote_nb[n].offset,
803                                        remote_nb[n-1].offset);
804                                 GOTO(out, rc = -EINVAL);
805                         }
806                 }
807         }
808
809         size[1] = niocount * sizeof(*remote_nb);
810         rc = lustre_pack_msg(2, size, NULL, &req->rq_replen, &req->rq_repmsg);
811         if (rc)
812                 GOTO(out, rc);
813
814         req->rq_status = obd_san_preprw(cmd, req->rq_export, &body->oa,
815                                         objcount, ioo, niocount, remote_nb);
816
817         if (req->rq_status)
818                 GOTO(out, rc = 0);
819
820         repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
821         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
822
823         res_nb = lustre_msg_buf(req->rq_repmsg, 1, size[1]);
824         memcpy(res_nb, remote_nb, size[1]);
825         rc = 0;
826 out:
827         if (rc) {
828                 OBD_FREE(req->rq_repmsg, req->rq_replen);
829                 req->rq_repmsg = NULL;
830                 req->rq_status = rc;
831                 ptlrpc_error(req);
832         } else
833                 ptlrpc_reply(req);
834
835         return rc;
836 }
837
838 static int ost_log_cancel(struct ptlrpc_request *req)
839 {
840         struct lustre_handle *conn;
841         struct llog_cookie *logcookies;
842         int num_cookies, rc = 0;
843         ENTRY;
844
845         logcookies = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*logcookies));
846         if (logcookies == NULL) {
847                 DEBUG_REQ(D_HA, req, "no cookies sent");
848                 RETURN(-EFAULT);
849         }
850         num_cookies = req->rq_reqmsg->buflens[0] / sizeof(*logcookies);
851
852         /* workaround until we don't need to send replies */
853         rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
854         if (rc)
855                 RETURN(rc);
856         req->rq_repmsg->status = 0;
857         /* end workaround */
858
859         conn = (struct lustre_handle *)&req->rq_reqmsg->handle;
860         rc = obd_log_cancel(conn, NULL, num_cookies, logcookies, 0);
861
862         RETURN(rc);
863 }
864
865 static int ost_set_info(struct ptlrpc_request *req)
866 {
867         struct lustre_handle *conn;
868         char *key;
869         int keylen, rc = 0;
870         ENTRY;
871
872         key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
873         if (key == NULL) {
874                 DEBUG_REQ(D_HA, req, "no set_info key");
875                 RETURN(-EFAULT);
876         }
877         keylen = req->rq_reqmsg->buflens[0];
878
879         rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
880         if (rc)
881                 RETURN(rc);
882
883         conn = (struct lustre_handle *)&req->rq_reqmsg->handle;
884         rc = obd_set_info(conn, keylen, key, 0, NULL);
885         req->rq_repmsg->status = 0;
886         RETURN(rc);
887 }
888
889 static int filter_recovery_request(struct ptlrpc_request *req,
890                                    struct obd_device *obd, int *process)
891 {
892         switch (req->rq_reqmsg->opc) {
893         case OST_CONNECT: /* This will never get here, but for completeness. */
894         case OST_DISCONNECT:
895                *process = 1;
896                RETURN(0);
897
898         case OBD_PING:
899         case OST_CLOSE:
900         case OST_CREATE:
901         case OST_DESTROY:
902         case OST_OPEN:
903         case OST_PUNCH:
904         case OST_SETATTR:
905         case OST_SYNCFS:
906         case OST_WRITE:
907         case OBD_LOG_CANCEL:
908         case LDLM_ENQUEUE:
909                 *process = target_queue_recovery_request(req, obd);
910                 RETURN(0);
911
912         default:
913                 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
914                 *process = 0;
915                 /* XXX what should we set rq_status to here? */
916                 req->rq_status = -EAGAIN;
917                 RETURN(ptlrpc_error(req));
918         }
919 }
920
921
922
923 static int ost_handle(struct ptlrpc_request *req)
924 {
925         struct obd_trans_info trans_info = { 0, };
926         struct obd_trans_info *oti = &trans_info;
927         int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
928         ENTRY;
929
930         /* XXX identical to MDS */
931         if (req->rq_reqmsg->opc != OST_CONNECT) {
932                 struct obd_device *obd;
933                 int abort_recovery, recovering;
934
935                 if (req->rq_export == NULL) {
936                         CDEBUG(D_HA, "operation %d on unconnected OST\n",
937                                req->rq_reqmsg->opc);
938                         req->rq_status = -ENOTCONN;
939                         GOTO(out, rc = -ENOTCONN);
940                 }
941
942                 obd = req->rq_export->exp_obd;
943
944                 /* Check for aborted recovery. */
945                 spin_lock_bh(&obd->obd_processing_task_lock);
946                 abort_recovery = obd->obd_abort_recovery;
947                 recovering = obd->obd_recovering;
948                 spin_unlock_bh(&obd->obd_processing_task_lock);
949                 if (abort_recovery) {
950                         target_abort_recovery(obd);
951                 } else if (recovering) {
952                         rc = filter_recovery_request(req, obd, &should_process);
953                         if (rc || !should_process)
954                                 RETURN(rc);
955                 }
956         }
957
958         if (strcmp(req->rq_obd->obd_type->typ_name, "ost") != 0)
959                 GOTO(out, rc = -EINVAL);
960
961         oti_init(oti, req);
962
963         switch (req->rq_reqmsg->opc) {
964         case OST_CONNECT:
965                 CDEBUG(D_INODE, "connect\n");
966                 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
967                 rc = target_handle_connect(req, ost_handle);
968                 break;
969         case OST_DISCONNECT:
970                 CDEBUG(D_INODE, "disconnect\n");
971                 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
972                 rc = target_handle_disconnect(req);
973                 break;
974         case OST_CREATE:
975                 CDEBUG(D_INODE, "create\n");
976                 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
977                 rc = ost_create(req, oti);
978                 break;
979         case OST_DESTROY:
980                 CDEBUG(D_INODE, "destroy\n");
981                 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
982                 rc = ost_destroy(req, oti);
983                 break;
984         case OST_GETATTR:
985                 CDEBUG(D_INODE, "getattr\n");
986                 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
987                 rc = ost_getattr(req);
988                 break;
989         case OST_SETATTR:
990                 CDEBUG(D_INODE, "setattr\n");
991                 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
992                 rc = ost_setattr(req, oti);
993                 break;
994         case OST_OPEN:
995                 CDEBUG(D_INODE, "open\n");
996                 OBD_FAIL_RETURN(OBD_FAIL_OST_OPEN_NET, 0);
997                 rc = ost_open(req, oti);
998                 break;
999         case OST_CLOSE:
1000                 CDEBUG(D_INODE, "close\n");
1001                 OBD_FAIL_RETURN(OBD_FAIL_OST_CLOSE_NET, 0);
1002                 rc = ost_close(req, oti);
1003                 break;
1004         case OST_WRITE:
1005                 CDEBUG(D_INODE, "write\n");
1006                 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1007                 rc = ost_brw_write(req, oti);
1008                 /* ost_brw sends its own replies */
1009                 RETURN(rc);
1010         case OST_READ:
1011                 CDEBUG(D_INODE, "read\n");
1012                 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1013                 rc = ost_brw_read(req);
1014                 /* ost_brw sends its own replies */
1015                 RETURN(rc);
1016         case OST_SAN_READ:
1017                 CDEBUG(D_INODE, "san read\n");
1018                 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1019                 rc = ost_san_brw(req, OBD_BRW_READ);
1020                 /* ost_san_brw sends its own replies */
1021                 RETURN(rc);
1022         case OST_SAN_WRITE:
1023                 CDEBUG(D_INODE, "san write\n");
1024                 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1025                 rc = ost_san_brw(req, OBD_BRW_WRITE);
1026                 /* ost_san_brw sends its own replies */
1027                 RETURN(rc);
1028         case OST_PUNCH:
1029                 CDEBUG(D_INODE, "punch\n");
1030                 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
1031                 rc = ost_punch(req, oti);
1032                 break;
1033         case OST_STATFS:
1034                 CDEBUG(D_INODE, "statfs\n");
1035                 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
1036                 rc = ost_statfs(req);
1037                 break;
1038         case OST_SYNCFS:
1039                 CDEBUG(D_INODE, "sync\n");
1040                 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNCFS_NET, 0);
1041                 rc = ost_syncfs(req);
1042                 break;
1043         case OST_SET_INFO:
1044                 DEBUG_REQ(D_INODE, req, "set_info");
1045                 rc = ost_set_info(req);
1046         case OBD_PING:
1047                 DEBUG_REQ(D_INODE, req, "ping");
1048                 rc = target_handle_ping(req);
1049                 break;
1050         case OBD_LOG_CANCEL:
1051                 CDEBUG(D_INODE, "log cancel\n");
1052                 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1053                 rc = ost_log_cancel(req);
1054                 break;
1055         case LDLM_ENQUEUE:
1056                 CDEBUG(D_INODE, "enqueue\n");
1057                 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1058                 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1059                                          ldlm_server_blocking_ast);
1060                 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1061                 break;
1062         case LDLM_CONVERT:
1063                 CDEBUG(D_INODE, "convert\n");
1064                 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1065                 rc = ldlm_handle_convert(req);
1066                 break;
1067         case LDLM_CANCEL:
1068                 CDEBUG(D_INODE, "cancel\n");
1069                 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1070                 rc = ldlm_handle_cancel(req);
1071                 break;
1072         case LDLM_BL_CALLBACK:
1073         case LDLM_CP_CALLBACK:
1074                 CDEBUG(D_INODE, "callback\n");
1075                 CERROR("callbacks should not happen on OST\n");
1076                 /* fall through */
1077         default:
1078                 CERROR("Unexpected opcode %d\n", req->rq_reqmsg->opc);
1079                 req->rq_status = -ENOTSUPP;
1080                 rc = ptlrpc_error(req);
1081                 RETURN(rc);
1082         }
1083
1084         EXIT;
1085         /* If we're DISCONNECTing, the export_data is already freed */
1086         if (!rc && req->rq_reqmsg->opc != OST_DISCONNECT) {
1087                 struct obd_device *obd  = req->rq_export->exp_obd;
1088                 if (!obd->obd_no_transno) {
1089                         req->rq_repmsg->last_committed =
1090                                 obd->obd_last_committed;
1091                 } else {
1092                         DEBUG_REQ(D_IOCTL, req,
1093                                   "not sending last_committed update");
1094                 }
1095                 CDEBUG(D_INFO, "last_committed "LPU64", xid "LPX64"\n",
1096                        obd->obd_last_committed, req->rq_xid);
1097         }
1098
1099 out:
1100         if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1101                 struct obd_device *obd = req->rq_export->exp_obd;
1102
1103                 if (obd && obd->obd_recovering) {
1104                         DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1105                         return target_queue_final_reply(req, rc);
1106                 }
1107                 /* Lost a race with recovery; let the error path DTRT. */
1108                 rc = req->rq_status = -ENOTCONN;
1109         }
1110
1111         if (!rc)
1112                 oti_to_request(oti, req);
1113
1114         target_send_reply(req, rc, fail);
1115         return 0;
1116 }
1117
1118 static int ost_setup(struct obd_device *obddev, obd_count len, void *buf)
1119 {
1120         struct ost_obd *ost = &obddev->u.ost;
1121         int err, i;
1122         ENTRY;
1123
1124 #ifdef ENABLE_ORPHANS
1125         err = llog_start_commit_thread();
1126         if (err < 0)
1127                 RETURN(err);
1128 #endif
1129
1130         ost->ost_service = ptlrpc_init_svc(OST_NEVENTS, OST_NBUFS,
1131                                            OST_BUFSIZE, OST_MAXREQSIZE,
1132                                            OST_REQUEST_PORTAL, OSC_REPLY_PORTAL,
1133                                            ost_handle, "ost", obddev);
1134         if (!ost->ost_service) {
1135                 CERROR("failed to start service\n");
1136                 RETURN(-ENOMEM);
1137         }
1138
1139         for (i = 0; i < OST_NUM_THREADS; i++) {
1140                 char name[32];
1141                 sprintf(name, "ll_ost_%02d", i);
1142                 err = ptlrpc_start_thread(obddev, ost->ost_service, name);
1143                 if (err) {
1144                         CERROR("error starting thread #%d: rc %d\n", i, err);
1145                         RETURN(-EINVAL);
1146                 }
1147         }
1148
1149         RETURN(0);
1150 }
1151
1152 static int ost_cleanup(struct obd_device *obddev, int flags)
1153 {
1154         struct ost_obd *ost = &obddev->u.ost;
1155         int err = 0;
1156         ENTRY;
1157
1158         if (obddev->obd_recovering)
1159                 target_cancel_recovery_timer(obddev);
1160
1161         ptlrpc_stop_all_threads(ost->ost_service);
1162         ptlrpc_unregister_service(ost->ost_service);
1163
1164         RETURN(err);
1165 }
1166
1167 int ost_attach(struct obd_device *dev, obd_count len, void *data)
1168 {
1169         struct lprocfs_static_vars lvars;
1170
1171         lprocfs_init_vars(ost,&lvars);
1172         return lprocfs_obd_attach(dev, lvars.obd_vars);
1173 }
1174
1175 int ost_detach(struct obd_device *dev)
1176 {
1177         return lprocfs_obd_detach(dev);
1178 }
1179
1180 /* I don't think this function is ever used, since nothing
1181  * connects directly to this module.
1182  */
1183 static int ost_connect(struct lustre_handle *conn,
1184                        struct obd_device *obd, struct obd_uuid *cluuid)
1185 {
1186         struct obd_export *exp;
1187         int rc;
1188         ENTRY;
1189
1190         if (!conn || !obd || !cluuid)
1191                 RETURN(-EINVAL);
1192
1193         rc = class_connect(conn, obd, cluuid);
1194         if (rc)
1195                 RETURN(rc);
1196         exp = class_conn2export(conn);
1197         LASSERT(exp);
1198         class_export_put(exp);
1199
1200         RETURN(0);
1201 }
1202
1203 /* use obd ops to offer management infrastructure */
1204 static struct obd_ops ost_obd_ops = {
1205         o_owner:        THIS_MODULE,
1206         o_attach:       ost_attach,
1207         o_detach:       ost_detach,
1208         o_setup:        ost_setup,
1209         o_cleanup:      ost_cleanup,
1210         o_connect:      ost_connect,
1211 };
1212
1213 static int __init ost_init(void)
1214 {
1215         struct lprocfs_static_vars lvars;
1216         ENTRY;
1217
1218         lprocfs_init_vars(ost,&lvars);
1219         RETURN(class_register_type(&ost_obd_ops, lvars.module_vars,
1220                                    LUSTRE_OST_NAME));
1221 }
1222
1223 static void /*__exit*/ ost_exit(void)
1224 {
1225         class_unregister_type(LUSTRE_OST_NAME);
1226 }
1227
1228 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1229 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1230 MODULE_LICENSE("GPL");
1231
1232 module_init(ost_init);
1233 module_exit(ost_exit);