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