Whamcloud - gitweb
b=585183
[fs/lustre-release.git] / lustre / osc / osc_request.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *  This code is issued under the GNU General Public License.
7  *  See the file COPYING in this distribution
8  *
9  *  Author Peter Braam <braam@clusterfs.com>
10  *
11  *  This server is single threaded at present (but can easily be multi
12  *  threaded). For testing and management it is treated as an
13  *  obd_device, although it does not export a full OBD method table
14  *  (the requests are coming in over the wire, so object target
15  *  modules do not have a full method table.)
16  *
17  */
18
19 #define EXPORT_SYMTAB
20 #define DEBUG_SUBSYSTEM S_OSC
21
22 #include <linux/module.h>
23 #include <linux/lustre_dlm.h>
24 #include <linux/lustre_mds.h> /* for mds_objid */
25 #include <linux/obd_ost.h>
26 #include <linux/obd_lov.h>
27 #include <linux/init.h>
28 #include <linux/lustre_ha.h>
29
30 static int osc_getattr(struct lustre_handle *conn, struct obdo *oa, 
31                        struct lov_stripe_md *md)
32 {
33         struct ptlrpc_request *request;
34         struct ost_body *body;
35         int rc, size = sizeof(*body);
36         ENTRY;
37
38         request = ptlrpc_prep_req2(conn, OST_GETATTR, 1, &size, NULL);
39         if (!request)
40                 RETURN(-ENOMEM);
41
42         body = lustre_msg_buf(request->rq_reqmsg, 0);
43 #warning FIXME: pack only valid fields instead of memcpy, endianness
44         memcpy(&body->oa, oa, sizeof(*oa));
45
46         request->rq_replen = lustre_msg_size(1, &size);
47
48         rc = ptlrpc_queue_wait(request);
49         rc = ptlrpc_check_status(request, rc);
50         if (rc) {
51                 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
52                 GOTO(out, rc);
53         }
54
55         body = lustre_msg_buf(request->rq_repmsg, 0);
56         CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
57         if (oa)
58                 memcpy(oa, &body->oa, sizeof(*oa));
59
60         EXIT;
61  out:
62         ptlrpc_free_req(request);
63         return rc;
64 }
65
66 static int osc_open(struct lustre_handle *conn, struct obdo *oa,
67                     struct lov_stripe_md *md)
68 {
69         struct ptlrpc_request *request;
70         struct ost_body *body;
71         int rc, size = sizeof(*body);
72         ENTRY;
73
74         request = ptlrpc_prep_req2(conn, OST_OPEN, 1, &size, NULL);
75         if (!request)
76                 RETURN(-ENOMEM);
77
78         body = lustre_msg_buf(request->rq_reqmsg, 0);
79 #warning FIXME: pack only valid fields instead of memcpy, endianness
80         memcpy(&body->oa, oa, sizeof(*oa));
81
82         request->rq_replen = lustre_msg_size(1, &size);
83
84         rc = ptlrpc_queue_wait(request);
85         rc = ptlrpc_check_status(request, rc);
86         if (rc)
87                 GOTO(out, rc);
88
89         body = lustre_msg_buf(request->rq_repmsg, 0);
90         CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
91         if (oa)
92                 memcpy(oa, &body->oa, sizeof(*oa));
93
94         EXIT;
95  out:
96         ptlrpc_free_req(request);
97         return rc;
98 }
99
100 static int osc_close(struct lustre_handle *conn, struct obdo *oa,
101                      struct lov_stripe_md *md)
102 {
103         struct ptlrpc_request *request;
104         struct ost_body *body;
105         int rc, size = sizeof(*body);
106         ENTRY;
107
108         request = ptlrpc_prep_req2(conn, OST_CLOSE, 1, &size, NULL);
109         if (!request)
110                 RETURN(-ENOMEM);
111
112         body = lustre_msg_buf(request->rq_reqmsg, 0);
113 #warning FIXME: pack only valid fields instead of memcpy, endianness
114         memcpy(&body->oa, oa, sizeof(*oa));
115
116         request->rq_replen = lustre_msg_size(1, &size);
117
118         rc = ptlrpc_queue_wait(request);
119         rc = ptlrpc_check_status(request, rc);
120         if (rc)
121                 GOTO(out, rc);
122
123         body = lustre_msg_buf(request->rq_repmsg, 0);
124         CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
125         if (oa)
126                 memcpy(oa, &body->oa, sizeof(*oa));
127
128         EXIT;
129  out:
130         ptlrpc_free_req(request);
131         return rc;
132 }
133
134 static int osc_setattr(struct lustre_handle *conn, struct obdo *oa,
135                        struct lov_stripe_md *md)
136 {
137         struct ptlrpc_request *request;
138         struct ost_body *body;
139         int rc, size = sizeof(*body);
140         ENTRY;
141
142         request = ptlrpc_prep_req2(conn, OST_SETATTR, 1, &size, NULL);
143         if (!request)
144                 RETURN(-ENOMEM);
145
146         body = lustre_msg_buf(request->rq_reqmsg, 0);
147         memcpy(&body->oa, oa, sizeof(*oa));
148
149         request->rq_replen = lustre_msg_size(1, &size);
150
151         rc = ptlrpc_queue_wait(request);
152         rc = ptlrpc_check_status(request, rc);
153         GOTO(out, rc);
154
155  out:
156         ptlrpc_free_req(request);
157         return rc;
158 }
159
160 static int osc_create(struct lustre_handle *conn, struct obdo *oa,
161                       struct lov_stripe_md **ea)
162 {
163         struct ptlrpc_request *request;
164         struct ost_body *body;
165         int rc, size = sizeof(*body);
166         ENTRY;
167
168         if (!oa) {
169                 CERROR("oa NULL\n");
170                 RETURN(-EINVAL);
171         }
172
173         if (!ea) {
174                 LBUG();
175         }
176
177         if (!*ea) {
178                 OBD_ALLOC(*ea, oa->o_easize);
179                 if (!*ea)
180                         RETURN(-ENOMEM);
181                 (*ea)->lmd_easize = oa->o_easize;
182         }
183
184         request = ptlrpc_prep_req2(conn, OST_CREATE, 1, &size, NULL);
185         if (!request)
186                 RETURN(-ENOMEM);
187
188         body = lustre_msg_buf(request->rq_reqmsg, 0);
189         memcpy(&body->oa, oa, sizeof(*oa));
190
191         request->rq_replen = lustre_msg_size(1, &size);
192
193         rc = ptlrpc_queue_wait(request);
194         rc = ptlrpc_check_status(request, rc);
195         if (rc)
196                 GOTO(out, rc);
197
198         body = lustre_msg_buf(request->rq_repmsg, 0);
199         memcpy(oa, &body->oa, sizeof(*oa));
200
201         (*ea)->lmd_object_id = oa->o_id;
202         (*ea)->lmd_stripe_count = 1;
203         EXIT;
204  out:
205         ptlrpc_free_req(request);
206         return rc;
207 }
208
209 static int osc_punch(struct lustre_handle *conn, struct obdo *oa,
210                      struct lov_stripe_md *md, obd_size start,
211                      obd_size end)
212 {
213         struct ptlrpc_request *request;
214         struct ost_body *body;
215         int rc, size = sizeof(*body);
216         ENTRY;
217
218         if (!oa) {
219                 CERROR("oa NULL\n");
220                 RETURN(-EINVAL);
221         }
222
223         request = ptlrpc_prep_req2(conn, OST_PUNCH, 1, &size, NULL);
224         if (!request)
225                 RETURN(-ENOMEM);
226
227         body = lustre_msg_buf(request->rq_reqmsg, 0);
228 #warning FIXME: pack only valid fields instead of memcpy, endianness, valid
229         memcpy(&body->oa, oa, sizeof(*oa));
230
231         /* overload the blocks and size fields in the oa with start/end */ 
232 #warning FIXME: endianness, size=start, blocks=end?
233         body->oa.o_blocks = start;
234         body->oa.o_size = end;
235         body->oa.o_valid |= OBD_MD_FLBLOCKS | OBD_MD_FLSIZE;
236
237         request->rq_replen = lustre_msg_size(1, &size);
238
239         rc = ptlrpc_queue_wait(request);
240         rc = ptlrpc_check_status(request, rc);
241         if (rc)
242                 GOTO(out, rc);
243
244         body = lustre_msg_buf(request->rq_repmsg, 0);
245         memcpy(oa, &body->oa, sizeof(*oa));
246
247         EXIT;
248  out:
249         ptlrpc_free_req(request);
250         return rc;
251 }
252
253 static int osc_destroy(struct lustre_handle *conn, struct obdo *oa,
254                        struct lov_stripe_md *ea)
255 {
256         struct ptlrpc_request *request;
257         struct ost_body *body;
258         int rc, size = sizeof(*body);
259         ENTRY;
260
261         if (!oa) {
262                 CERROR("oa NULL\n");
263                 RETURN(-EINVAL);
264         }
265         request = ptlrpc_prep_req2(conn, OST_DESTROY, 1, &size, NULL);
266         if (!request)
267                 RETURN(-ENOMEM);
268
269         body = lustre_msg_buf(request->rq_reqmsg, 0);
270 #warning FIXME: pack only valid fields instead of memcpy, endianness
271         memcpy(&body->oa, oa, sizeof(*oa));
272
273         request->rq_replen = lustre_msg_size(1, &size);
274
275         rc = ptlrpc_queue_wait(request);
276         rc = ptlrpc_check_status(request, rc);
277         if (rc)
278                 GOTO(out, rc);
279
280         body = lustre_msg_buf(request->rq_repmsg, 0);
281         memcpy(oa, &body->oa, sizeof(*oa));
282
283         EXIT;
284  out:
285         ptlrpc_free_req(request);
286         return rc;
287 }
288
289 struct osc_brw_cb_data {
290         brw_callback_t callback;
291         void *cb_data;
292         void *obd_data;
293         size_t obd_size;
294 };
295
296 /* Our bulk-unmapping bottom half. */
297 static void unmap_and_decref_bulk_desc(void *data)
298 {
299         struct ptlrpc_bulk_desc *desc = data;
300         struct list_head *tmp;
301         ENTRY;
302
303         /* This feels wrong to me. */
304         list_for_each(tmp, &desc->b_page_list) {
305                 struct ptlrpc_bulk_page *bulk;
306                 bulk = list_entry(tmp, struct ptlrpc_bulk_page, b_link);
307
308                 kunmap(bulk->b_page);
309         }
310
311         ptlrpc_bulk_decref(desc);
312         EXIT;
313 }
314
315 static void brw_finish(struct ptlrpc_bulk_desc *desc, void *data)
316 {
317         struct osc_brw_cb_data *cb_data = data;
318         int err = 0;
319         ENTRY;
320
321         if (desc->b_flags & PTL_RPC_FL_TIMEOUT) {
322                 err = (desc->b_flags & PTL_RPC_FL_INTR ? -ERESTARTSYS : 
323                        -ETIMEDOUT);
324         }
325
326         if (cb_data->callback)
327                 cb_data->callback(cb_data->cb_data, err, CB_PHASE_FINISH);
328
329         OBD_FREE(cb_data->obd_data, cb_data->obd_size);
330         OBD_FREE(cb_data, sizeof(*cb_data));
331
332         /* We can't kunmap the desc from interrupt context, so we do it from
333          * the bottom half above. */
334         INIT_TQUEUE(&desc->b_queue, 0, 0);
335         PREPARE_TQUEUE(&desc->b_queue, unmap_and_decref_bulk_desc, desc);
336         schedule_task(&desc->b_queue);
337
338         EXIT;
339 }
340
341 static int osc_brw_read(struct lustre_handle *conn, struct lov_stripe_md *md,
342                         obd_count page_count, struct brw_page *pga,
343                         brw_callback_t callback, struct io_cb_data *data)
344 {
345         struct ptlrpc_connection *connection = client_conn2cli(conn)->cl_conn;
346         struct ptlrpc_request *request = NULL;
347         struct ptlrpc_bulk_desc *desc = NULL;
348         struct ost_body *body;
349         struct osc_brw_cb_data *cb_data = NULL;
350         int rc, size[3] = {sizeof(*body)};
351         void *iooptr, *nioptr;
352         int mapped = 0;
353         __u32 xid;
354         ENTRY;
355
356         size[1] = sizeof(struct obd_ioobj);
357         size[2] = page_count * sizeof(struct niobuf_remote);
358
359         request = ptlrpc_prep_req2(conn, OST_READ, 3, size, NULL);
360         if (!request)
361                 RETURN(-ENOMEM);
362
363         body = lustre_msg_buf(request->rq_reqmsg, 0);
364
365         desc = ptlrpc_prep_bulk(connection);
366         if (!desc)
367                 GOTO(out_req, rc = -ENOMEM);
368         desc->b_portal = OST_BULK_PORTAL;
369         desc->b_cb = brw_finish;
370         OBD_ALLOC(cb_data, sizeof(*cb_data));
371         if (!cb_data)
372                 GOTO(out_desc, rc = -ENOMEM);
373
374         cb_data->callback = callback;
375         cb_data->cb_data = data;
376         data->desc = desc;
377         desc->b_cb_data = cb_data;
378
379         iooptr = lustre_msg_buf(request->rq_reqmsg, 1);
380         nioptr = lustre_msg_buf(request->rq_reqmsg, 2);
381         ost_pack_ioo(&iooptr, md, page_count);
382         /* end almost identical to brw_write case */
383
384         spin_lock(&connection->c_lock);
385         xid = ++connection->c_xid_out;       /* single xid for all pages */
386         spin_unlock(&connection->c_lock);
387
388         for (mapped = 0; mapped < page_count; mapped++) {
389                 struct ptlrpc_bulk_page *bulk = ptlrpc_prep_bulk_page(desc);
390                 if (bulk == NULL)
391                         GOTO(out_unmap, rc = -ENOMEM);
392
393                 bulk->b_xid = xid;           /* single xid for all pages */
394
395                 bulk->b_buf = kmap(pga[mapped].pg);
396                 bulk->b_page = pga[mapped].pg;
397                 bulk->b_buflen = PAGE_SIZE;
398                 ost_pack_niobuf(&nioptr, pga[mapped].off, pga[mapped].count,
399                                 pga[mapped].flag, bulk->b_xid);
400         }
401
402         /*
403          * Register the bulk first, because the reply could arrive out of order,
404          * and we want to be ready for the bulk data.
405          *
406          * One reference is released when brw_finish is complete, the
407          * other here when we finish waiting on it if we don't have a callback.
408          *
409          * We don't reference the bulk descriptor again here if there is a
410          * callback, so we don't need an additional refcount on it.
411          *
412          * On error, we never do the brw_finish, so we handle all decrefs.
413          */
414         rc = ptlrpc_register_bulk(desc);
415         if (rc)
416                 GOTO(out_unmap, rc);
417
418         request->rq_replen = lustre_msg_size(1, size);
419         rc = ptlrpc_queue_wait(request);
420         rc = ptlrpc_check_status(request, rc);
421
422         /* XXX: Mike, this is the only place I'm not sure of.  If we had
423          *      an error here, will we always call brw_finish?  If yes, then
424          *      out_desc_2 will do too much and we should jump to out_desc.
425          *      If maybe, then we are screwed, and we need to set things up
426          *      so that bulk_sink_callback is called for each bulk page,
427          *      even on error so brw_finish is always called.  It would need
428          *      to be passed an error code as a parameter to know what to do.
429          *
430          *      That would also help with the partial completion case, so
431          *      we could say in brw_finish "these pages are done, don't
432          *      restart them" and osc_brw callers can know this.
433          */
434         if (rc)
435                 GOTO(out_unmap, rc);
436
437         /* Callbacks cause asynchronous handling. */
438         rc = callback(data, 0, CB_PHASE_START); 
439
440         EXIT;
441 out_desc:
442         ptlrpc_bulk_decref(desc);
443 out_req:
444         ptlrpc_req_finished(request);
445         RETURN(rc);
446
447         /* Clean up on error. */
448 out_unmap:
449         while (mapped-- > 0)
450                 kunmap(page_array[mapped]);
451         OBD_FREE(cb_data, sizeof(*cb_data));
452         goto out_desc;
453 }
454
455 static int osc_brw_write(struct lustre_handle *conn,
456                          struct lov_stripe_md *md, obd_count page_count,
457                          struct brw_page *pga,
458                          brw_callback_t callback, struct io_cb_data *data)
459 {
460         struct ptlrpc_connection *connection = client_conn2cli(conn)->cl_conn;
461         struct ptlrpc_request *request = NULL;
462         struct ptlrpc_bulk_desc *desc = NULL;
463         struct ost_body *body;
464         struct niobuf_local *local = NULL;
465         struct niobuf_remote *remote;
466         struct osc_brw_cb_data *cb_data = NULL;
467         int rc, j, size[3] = {sizeof(*body)};
468         void *iooptr, *nioptr;
469         int mapped = 0;
470         ENTRY;
471
472         size[1] = sizeof(struct obd_ioobj);
473         size[2] = page_count * sizeof(*remote);
474
475         request = ptlrpc_prep_req2(conn, OST_WRITE, 3, size, NULL);
476         if (!request)
477                 RETURN(-ENOMEM);
478
479         body = lustre_msg_buf(request->rq_reqmsg, 0);
480
481         desc = ptlrpc_prep_bulk(connection);
482         if (!desc)
483                 GOTO(out_req, rc = -ENOMEM);
484         desc->b_portal = OSC_BULK_PORTAL;
485         desc->b_cb = brw_finish;
486         OBD_ALLOC(cb_data, sizeof(*cb_data));
487         if (!cb_data)
488                 GOTO(out_desc, rc = -ENOMEM);
489
490         cb_data->callback = callback;
491         cb_data->cb_data = data;
492         data->desc = desc;
493         desc->b_cb_data = cb_data;
494
495         iooptr = lustre_msg_buf(request->rq_reqmsg, 1);
496         nioptr = lustre_msg_buf(request->rq_reqmsg, 2);
497         ost_pack_ioo(&iooptr, md, page_count);
498         /* end almost identical to brw_read case */
499
500         OBD_ALLOC(local, page_count * sizeof(*local));
501         if (!local)
502                 GOTO(out_cb, rc = -ENOMEM);
503
504         cb_data->obd_data = local;
505         cb_data->obd_size = page_count * sizeof(*local);
506
507         for (mapped = 0; mapped < page_count; mapped++) {
508                 local[mapped].addr = kmap(pga[mapped].pg);
509                 local[mapped].offset = pga[mapped].off;
510                 local[mapped].len = pga[mapped].count;
511                 ost_pack_niobuf(&nioptr, pga[mapped].off, pga[mapped].count,
512                                 pga[mapped].flag, 0);
513         }
514
515         size[1] = page_count * sizeof(*remote);
516         request->rq_replen = lustre_msg_size(2, size);
517         rc = ptlrpc_queue_wait(request);
518         rc = ptlrpc_check_status(request, rc);
519         if (rc)
520                 GOTO(out_unmap, rc);
521
522         nioptr = lustre_msg_buf(request->rq_repmsg, 1);
523         if (!nioptr)
524                 GOTO(out_unmap, rc = -EINVAL);
525
526         if (request->rq_repmsg->buflens[1] != size[1]) {
527                 CERROR("buffer length wrong (%d vs. %d)\n",
528                        request->rq_repmsg->buflens[1], size[1]);
529                 GOTO(out_unmap, rc = -EINVAL);
530         }
531
532         for (j = 0; j < page_count; j++) {
533                 struct ptlrpc_bulk_page *bulk;
534
535                 ost_unpack_niobuf(&nioptr, &remote);
536
537                 bulk = ptlrpc_prep_bulk_page(desc);
538                 if (!bulk)
539                         GOTO(out_unmap, rc = -ENOMEM);
540
541                 bulk->b_buf = (void *)(unsigned long)local[j].addr;
542                 bulk->b_buflen = local[j].len;
543                 bulk->b_xid = remote->xid;
544                 bulk->b_page = pga[j].pg;
545         }
546
547         if (desc->b_page_count != page_count)
548                 LBUG();
549
550         /*
551          * One reference is released when brw_finish is complete, the
552          * other here when we finish waiting on it if we don't have a callback.
553          */
554         rc = ptlrpc_send_bulk(desc);
555
556         /* XXX: Mike, same question as in osc_brw_read. */
557         if (rc)
558                 GOTO(out_desc2, rc);
559
560         /* Callbacks cause asynchronous handling. */
561         rc = callback(data, 0, CB_PHASE_START);
562
563         EXIT;
564 out_desc:
565         ptlrpc_bulk_decref(desc);
566 out_req:
567         ptlrpc_req_finished(request);
568         return rc;
569
570         /* Clean up on error. */
571 out_desc2:
572         if (!callback)
573                 ptlrpc_bulk_decref(desc);
574 out_unmap:
575         while (mapped-- > 0)
576                 kunmap(pagearray[mapped]);
577
578         OBD_FREE(local, page_count * sizeof(*local));
579 out_cb:
580         OBD_FREE(cb_data, sizeof(*cb_data));
581         goto out_desc;
582 }
583
584 static int osc_brw(int cmd, struct lustre_handle *conn,
585                    struct lov_stripe_md *md, obd_count page_count,
586                    struct brw_page *pagear, brw_callback_t callback, 
587                    struct io_cb_data *data) 
588 {
589         if (cmd & OBD_BRW_WRITE)
590                 return osc_brw_write(conn, md, page_count, pagear, callback, data);
591         else
592                 return osc_brw_read(conn, md, page_count, pagear, callback, data);
593 }
594
595 static int osc_enqueue(struct lustre_handle *connh, struct lov_stripe_md *md, 
596                        struct lustre_handle *parent_lock, 
597                        __u32 type, void *extentp, int extent_len, __u32 mode,
598                        int *flags, void *callback, void *data, int datalen,
599                        struct lustre_handle *lockh)
600 {
601         __u64 res_id = { md->lmd_object_id };
602         struct obd_device *obddev = class_conn2obd(connh);
603         struct ldlm_extent *extent = extentp;
604         int rc;
605         __u32 mode2;
606
607         /* Filesystem locks are given a bit of special treatment: first we
608          * fixup the lock to start and end on page boundaries. */
609         extent->start &= PAGE_MASK;
610         extent->end = (extent->end + PAGE_SIZE - 1) & PAGE_MASK;
611
612         /* Next, search for already existing extent locks that will cover us */
613         //osc_con2dlmcl(conn, &cl, &connection, &rconn);
614         rc = ldlm_lock_match(obddev->obd_namespace, &res_id, type, extent,
615                              sizeof(extent), mode, lockh);
616         if (rc == 1) {
617                 /* We already have a lock, and it's referenced */
618                 return 0;
619         }
620
621         /* Next, search for locks that we can upgrade (if we're trying to write)
622          * or are more than we need (if we're trying to read).  Because the VFS
623          * and page cache already protect us locally, lots of readers/writers
624          * can share a single PW lock. */
625         if (mode == LCK_PW)
626                 mode2 = LCK_PR;
627         else
628                 mode2 = LCK_PW;
629
630         rc = ldlm_lock_match(obddev->obd_namespace, &res_id, type, extent,
631                              sizeof(extent), mode2, lockh);
632         if (rc == 1) {
633                 int flags;
634                 /* FIXME: This is not incredibly elegant, but it might
635                  * be more elegant than adding another parameter to
636                  * lock_match.  I want a second opinion. */
637                 ldlm_lock_addref(lockh, mode);
638                 ldlm_lock_decref(lockh, mode2);
639
640                 if (mode == LCK_PR)
641                         return 0;
642
643                 rc = ldlm_cli_convert(lockh, mode, &flags);
644                 if (rc)
645                         LBUG();
646
647                 return rc;
648         }
649
650         rc = ldlm_cli_enqueue(connh, NULL,obddev->obd_namespace,
651                               parent_lock, &res_id, type, extent,
652                               sizeof(extent), mode, flags, ldlm_completion_ast,
653                               callback, data, datalen, lockh);
654         return rc;
655 }
656
657 static int osc_cancel(struct lustre_handle *oconn, struct lov_stripe_md *md,
658                       __u32 mode, struct lustre_handle *lockh)
659 {
660         ENTRY;
661
662         ldlm_lock_decref(lockh, mode);
663
664         RETURN(0);
665 }
666
667 static int osc_statfs(struct lustre_handle *conn, struct statfs *sfs)
668 {
669         struct ptlrpc_request *request;
670         struct obd_statfs *osfs;
671         int rc, size = sizeof(*osfs);
672         ENTRY;
673
674         request = ptlrpc_prep_req2(conn, OST_STATFS, 0, NULL, NULL);
675         if (!request)
676                 RETURN(-ENOMEM);
677
678         request->rq_replen = lustre_msg_size(1, &size);
679
680         rc = ptlrpc_queue_wait(request);
681         rc = ptlrpc_check_status(request, rc);
682         if (rc) {
683                 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
684                 GOTO(out, rc);
685         }
686
687         osfs = lustre_msg_buf(request->rq_repmsg, 0);
688         obd_statfs_unpack(osfs, sfs);
689
690         EXIT;
691  out:
692         ptlrpc_free_req(request);
693         return rc;
694 }
695
696 struct obd_ops osc_obd_ops = {
697         o_setup:        client_obd_setup,
698         o_cleanup:      client_obd_cleanup,
699         o_statfs:       osc_statfs,
700         o_create:       osc_create,
701         o_destroy:      osc_destroy,
702         o_getattr:      osc_getattr,
703         o_setattr:      osc_setattr,
704         o_open:         osc_open,
705         o_close:        osc_close,
706         o_connect:      client_obd_connect,
707         o_disconnect:   client_obd_disconnect,
708         o_brw:          osc_brw,
709         o_punch:        osc_punch,
710         o_enqueue:      osc_enqueue,
711         o_cancel:       osc_cancel
712 };
713
714 static int __init osc_init(void)
715 {
716         return class_register_type(&osc_obd_ops, LUSTRE_OSC_NAME);
717 }
718
719 static void __exit osc_exit(void)
720 {
721         class_unregister_type(LUSTRE_OSC_NAME);
722 }
723
724 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
725 MODULE_DESCRIPTION("Lustre Object Storage Client (OSC) v1.0");
726 MODULE_LICENSE("GPL");
727
728 module_init(osc_init);
729 module_exit(osc_exit);