Whamcloud - gitweb
b=2313
[fs/lustre-release.git] / lustre / mds / mds_open.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2003 Cluster File Systems, Inc.
5  *   Author: Peter Braam <braam@clusterfs.com>
6  *   Author: Andreas Dilger <adilger@clusterfs.com>
7  *   Author: Phil Schwan <phil@clusterfs.com>
8  *   Author: Mike Shaver <shaver@clusterfs.com>
9  *
10  *   This file is part of Lustre, http://www.lustre.org.
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #ifndef EXPORT_SYMTAB
27 # define EXPORT_SYMTAB
28 #endif
29 #define DEBUG_SUBSYSTEM S_MDS
30
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
34 # include <linux/buffer_head.h>
35 # include <linux/workqueue.h>
36 #else
37 # include <linux/locks.h>
38 #endif
39
40 #include <linux/obd_class.h>
41 #include <linux/lustre_mds.h>
42 #include <linux/obd_lov.h>
43 #include <linux/lustre_fsfilt.h>
44 #include <linux/lprocfs_status.h>
45
46 #include "mds_internal.h"
47
48 /* Exported function from this file are:
49  *
50  * mds_open - called by the intent handler
51  * mds_close - an rpc handling function
52  * mds_pin - an rpc handling function - which will go away
53  * mds_mfd_close - for force closing files when a client dies
54  */
55
56 /* 
57  * MDS file data handling: file data holds a handle for a file opened
58  * by a client.
59  */
60
61 static void mds_mfd_addref(void *mfdp)
62 {
63         struct mds_file_data *mfd = mfdp;
64
65         atomic_inc(&mfd->mfd_refcount);
66         CDEBUG(D_INFO, "GETting mfd %p : new refcount %d\n", mfd,
67                atomic_read(&mfd->mfd_refcount));
68 }
69
70 struct mds_file_data *mds_mfd_new(void)
71 {
72         struct mds_file_data *mfd;
73
74         OBD_ALLOC(mfd, sizeof *mfd);
75         if (mfd == NULL) {
76                 CERROR("mds: out of memory\n");
77                 return NULL;
78         }
79
80         atomic_set(&mfd->mfd_refcount, 2);
81
82         INIT_LIST_HEAD(&mfd->mfd_handle.h_link);
83         class_handle_hash(&mfd->mfd_handle, mds_mfd_addref);
84
85         return mfd;
86 }
87
88 static struct mds_file_data *mds_handle2mfd(struct lustre_handle *handle)
89 {
90         ENTRY;
91         LASSERT(handle != NULL);
92         RETURN(class_handle2object(handle->cookie));
93 }
94
95 static void mds_mfd_put(struct mds_file_data *mfd)
96 {
97         CDEBUG(D_INFO, "PUTting mfd %p : new refcount %d\n", mfd,
98                atomic_read(&mfd->mfd_refcount) - 1);
99         LASSERT(atomic_read(&mfd->mfd_refcount) > 0 &&
100                 atomic_read(&mfd->mfd_refcount) < 0x5a5a);
101         if (atomic_dec_and_test(&mfd->mfd_refcount)) {
102                 LASSERT(list_empty(&mfd->mfd_handle.h_link));
103                 OBD_FREE(mfd, sizeof *mfd);
104         }
105 }
106
107 static void mds_mfd_destroy(struct mds_file_data *mfd)
108 {
109         class_handle_unhash(&mfd->mfd_handle);
110         mds_mfd_put(mfd);
111 }
112
113
114 /* Caller must hold mds->mds_epoch_sem */
115 static int mds_alloc_filterdata(struct inode *inode)
116 {
117         LASSERT(inode->i_filterdata == NULL);
118         OBD_ALLOC(inode->i_filterdata, sizeof(struct mds_filter_data));
119         if (inode->i_filterdata == NULL)
120                 return -ENOMEM;
121         LASSERT(igrab(inode) == inode);
122         return 0;
123 }
124
125 /* Caller must hold mds->mds_epoch_sem */
126 static void mds_free_filterdata(struct inode *inode)
127 {
128         LASSERT(inode->i_filterdata != NULL);
129         OBD_FREE(inode->i_filterdata, sizeof(struct mds_filter_data));
130         inode->i_filterdata = NULL;
131         iput(inode);
132 }
133
134 /* Write access to a file: executors cause a negative count, 
135  * writers a positive count.  The semaphore is needed to perform
136  * a check for the sign and then increment or decrement atomically.
137  *
138  * This code is closely tied to the allocation of the d_fsdata and the
139  * MDS epoch, so we use the same semaphore for the whole lot.
140  *
141  * We could use a different semaphore for each file, if it ever shows
142  * up in a profile, which it won't.
143  *
144  * epoch argument is nonzero during recovery */
145 static int mds_get_write_access(struct mds_obd *mds, struct inode *inode,
146                                 __u64 epoch)
147 {
148         int rc = 0;
149
150         down(&mds->mds_epoch_sem);
151
152         if (atomic_read(&inode->i_writecount) < 0) {
153                 up(&mds->mds_epoch_sem);
154                 RETURN(-ETXTBSY);
155         }
156
157
158         if (MDS_FILTERDATA(inode) && MDS_FILTERDATA(inode)->io_epoch != 0) {
159                 CDEBUG(D_INODE, "continuing MDS epoch "LPU64" for ino %lu/%u\n",
160                        MDS_FILTERDATA(inode)->io_epoch, inode->i_ino,
161                        inode->i_generation);
162                 goto out;
163         }
164
165         if (inode->i_filterdata == NULL)
166                 mds_alloc_filterdata(inode);
167         if (inode->i_filterdata == NULL) {
168                 rc = -ENOMEM;
169                 goto out;
170         }
171         if (epoch > mds->mds_io_epoch)
172                 mds->mds_io_epoch = epoch;
173         else
174                 mds->mds_io_epoch++;
175         MDS_FILTERDATA(inode)->io_epoch = mds->mds_io_epoch;
176         CDEBUG(D_INODE, "starting MDS epoch "LPU64" for ino %lu/%u\n",
177                mds->mds_io_epoch, inode->i_ino, inode->i_generation);
178  out:
179         if (rc == 0)
180                 atomic_inc(&inode->i_writecount);
181         up(&mds->mds_epoch_sem);
182         return rc;
183 }
184
185 /* Returns EAGAIN if the client needs to get size and/or cookies and close
186  * again -- which is never true if the file is about to be unlinked.  Otherwise
187  * returns the number of remaining writers. */
188 static int mds_put_write_access(struct mds_obd *mds, struct inode *inode,
189                                 struct mds_body *body, int unlinking)
190 {
191         int rc = 0;
192         ENTRY;
193
194         down(&mds->mds_epoch_sem);
195         atomic_dec(&inode->i_writecount);
196         rc = atomic_read(&inode->i_writecount);
197         if (rc > 0)
198                 GOTO(out, rc);
199 #if 0
200         if (!unlinking && !(body->valid & OBD_MD_FLSIZE))
201                 GOTO(out, rc = EAGAIN);
202 #endif
203         mds_free_filterdata(inode);
204  out:
205         up(&mds->mds_epoch_sem);
206         return rc;
207 }
208
209 static int mds_deny_write_access(struct mds_obd *mds, struct inode *inode)
210 {
211         ENTRY;
212         down(&mds->mds_epoch_sem);
213         if (atomic_read(&inode->i_writecount) > 0) {
214                 up(&mds->mds_epoch_sem);
215                 RETURN(-ETXTBSY);
216         }
217         atomic_dec(&inode->i_writecount);
218         up(&mds->mds_epoch_sem);
219         RETURN(0);
220 }
221
222 static void mds_allow_write_access(struct inode *inode)
223 {
224         ENTRY;
225         atomic_inc(&inode->i_writecount);
226 }
227
228 int mds_query_write_access(struct inode *inode)
229 {
230         ENTRY;
231         RETURN(atomic_read(&inode->i_writecount));
232 }
233
234 /* This replaces the VFS mds_dentry_open, it manages mfd and writecount */
235 static struct mds_file_data *mds_dentry_open(struct dentry *dentry,
236                                              struct vfsmount *mnt, int flags,
237                                              struct ptlrpc_request *req)
238 {
239         struct mds_export_data *med = &req->rq_export->exp_mds_data;
240         struct mds_obd *mds = mds_req2mds(req);
241         struct mds_file_data *mfd;
242         struct mds_body *body;
243         int error;
244         ENTRY;
245         
246         mfd = mds_mfd_new();
247         if (mfd == NULL) {
248                 CERROR("mds: out of memory\n");
249                 GOTO(cleanup_dentry, error = -ENOMEM);
250         }
251
252         body = lustre_msg_buf(req->rq_repmsg, 1, sizeof (*body));
253
254         if (flags & FMODE_WRITE) {
255                 /* FIXME: in recovery, need to pass old epoch here */
256                 error = mds_get_write_access(mds, dentry->d_inode, 0);
257                 if (error)
258                         GOTO(cleanup_mfd, error);
259                 body->io_epoch = MDS_FILTERDATA(dentry->d_inode)->io_epoch;
260         } else if (flags & FMODE_EXEC) {
261                 error = mds_deny_write_access(mds, dentry->d_inode);
262                 if (error)
263                         GOTO(cleanup_mfd, error);
264         }
265
266         dget(dentry);
267
268         /* Mark the file as open to handle open-unlink. */
269         mds_open_orphan_inc(dentry->d_inode);
270
271         mfd->mfd_mode = flags;
272         mfd->mfd_dentry = dentry;
273         mfd->mfd_xid = req->rq_xid;
274
275         spin_lock(&med->med_open_lock);
276         list_add(&mfd->mfd_list, &med->med_open_head);
277         spin_unlock(&med->med_open_lock);
278         mds_mfd_put(mfd);
279
280         body->handle.cookie = mfd->mfd_handle.h_cookie;
281
282         RETURN(mfd);
283
284 cleanup_mfd:
285         mds_mfd_put(mfd);
286         mds_mfd_destroy(mfd);
287 cleanup_dentry:
288         return ERR_PTR(error);
289 }
290
291 static void mds_objids_from_lmm(obd_id *ids, struct lov_mds_md *lmm,
292                                 struct lov_desc *desc)
293 {
294         int i;
295         for (i = 0; i < le32_to_cpu(lmm->lmm_stripe_count); i++) {
296                 ids[le32_to_cpu(lmm->lmm_objects[i].l_ost_idx)] =
297                         le64_to_cpu(lmm->lmm_objects[i].l_object_id);
298         }
299 }
300
301 /* Must be called with i_sem held */
302 static int mds_create_objects(struct ptlrpc_request *req, int offset,
303                               struct mds_update_record *rec,
304                               struct mds_obd *mds, struct obd_device *obd,
305                               struct inode *inode, void **handle, obd_id **ids)
306 {
307         struct obdo *oa;
308         struct obd_trans_info oti = { 0 };
309         struct mds_body *body;
310         struct lov_stripe_md *lsm = NULL;
311         struct lov_mds_md *lmm = NULL;
312         void *lmm_buf;
313         int rc, lmm_bufsize, lmm_size;
314         ENTRY;
315
316         if (rec->ur_flags & MDS_OPEN_DELAY_CREATE ||
317             !(rec->ur_flags & FMODE_WRITE))
318                 RETURN(0);
319
320         body = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*body));
321
322         if (!S_ISREG(inode->i_mode))
323                 RETURN(0);
324         if (body->valid & OBD_MD_FLEASIZE)
325                 RETURN(0);
326
327         OBD_ALLOC(*ids, mds->mds_lov_desc.ld_tgt_count * sizeof(**ids));
328         if (*ids == NULL)
329                 RETURN(-ENOMEM);
330         oti.oti_objid = *ids;
331
332         if (*handle == NULL)
333                 *handle = fsfilt_start(obd, inode, FSFILT_OP_CREATE, NULL);
334         if (IS_ERR(*handle)) {
335                 rc = PTR_ERR(*handle);
336                 *handle = NULL;
337                 GOTO(out_ids, rc);
338         }
339
340         /* replay case */
341         if (rec->ur_fid2->id) {
342                 body->valid |= OBD_MD_FLBLKSZ | OBD_MD_FLEASIZE;
343                 lmm_size = rec->ur_eadatalen;
344                 lmm = rec->ur_eadata;
345                 LASSERT(lmm);
346
347                 mds_objids_from_lmm(*ids, lmm, &mds->mds_lov_desc);
348
349                 lmm_buf = lustre_msg_buf(req->rq_repmsg, offset, 0);
350                 lmm_bufsize = req->rq_repmsg->buflens[offset];
351                 LASSERT(lmm_buf);
352                 LASSERT(lmm_bufsize >= lmm_size);
353                 memcpy(lmm_buf, lmm, lmm_size);
354                 rc = fsfilt_set_md(obd, inode, *handle, lmm, lmm_size);
355                 if (rc)
356                         CERROR("open replay failed to set md:%d\n", rc);
357                 RETURN(0);
358         }
359
360         oa = obdo_alloc();
361         if (oa == NULL)
362                 GOTO(out_ids, rc = -ENOMEM);
363         oa->o_mode = S_IFREG | 0600;
364         oa->o_id = inode->i_ino;
365         oa->o_generation = inode->i_generation;
366         oa->o_uid = 0; /* must have 0 uid / gid on OST */
367         oa->o_gid = 0;
368         oa->o_valid = OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FLTYPE |
369                 OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID;
370         oa->o_size = 0;
371
372         obdo_from_inode(oa, inode, OBD_MD_FLTYPE|OBD_MD_FLATIME|OBD_MD_FLMTIME|
373                         OBD_MD_FLCTIME);
374
375         /* check if things like lstripe/lfs stripe are sending us the ea */
376         if (rec->ur_flags & MDS_OPEN_HAS_EA) {
377                 rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, mds->mds_osc_exp,
378                                    0, &lsm, rec->ur_eadata);
379                 if (rc)
380                         GOTO(out_oa, rc);
381         }
382
383         rc = obd_create(mds->mds_osc_exp, oa, &lsm, &oti);
384         if (rc) {
385                 int level = D_ERROR;
386                 if (rc == -ENOSPC)
387                         level = D_INODE;
388                 CDEBUG(level, "error creating objects for inode %lu: rc = %d\n",
389                        inode->i_ino, rc);
390                 if (rc > 0) {
391                         CERROR("obd_create returned invalid rc %d\n", rc);
392                         rc = -EIO;
393                 }
394                 GOTO(out_oa, rc);
395         }
396
397         if (inode->i_size) {
398                 oa->o_size = inode->i_size;
399                 obdo_from_inode(oa, inode, OBD_MD_FLTYPE|OBD_MD_FLATIME|
400                                 OBD_MD_FLMTIME| OBD_MD_FLCTIME| OBD_MD_FLSIZE);
401                 rc = obd_setattr(mds->mds_osc_exp, oa, lsm, &oti);
402                 if (rc) {
403                         CERROR("error setting attrs for inode %lu: rc %d\n",
404                                inode->i_ino, rc);
405                         if (rc > 0) {
406                                 CERROR("obd_setattr returned bad rc %d\n", rc);
407                                 rc = -EIO;
408                         }
409                         GOTO(out_oa, rc);
410                 }
411         }
412
413         body->valid |= OBD_MD_FLBLKSZ | OBD_MD_FLEASIZE;
414         obdo_refresh_inode(inode, oa, OBD_MD_FLBLKSZ);
415
416         LASSERT(lsm && lsm->lsm_object_id);
417         lmm = NULL;
418         rc = obd_packmd(mds->mds_osc_exp, &lmm, lsm);
419         if (!rec->ur_fid2->id)
420                 obd_free_memmd(mds->mds_osc_exp, &lsm);
421         LASSERT(rc >= 0);
422         lmm_size = rc;
423         body->eadatasize = rc;
424         rc = fsfilt_set_md(obd, inode, *handle, lmm, lmm_size);
425         lmm_buf = lustre_msg_buf(req->rq_repmsg, offset, 0);
426         lmm_bufsize = req->rq_repmsg->buflens[offset];
427         LASSERT(lmm_buf);
428         LASSERT(lmm_bufsize >= lmm_size);
429
430         memcpy(lmm_buf, lmm, lmm_size);
431         obd_free_diskmd(mds->mds_osc_exp, &lmm);
432  out_oa:
433         oti_free_cookies(&oti);
434         obdo_free(oa);
435  out_ids:
436         if (rc) {
437                 OBD_FREE(*ids, mds->mds_lov_desc.ld_tgt_count * sizeof(**ids));
438                 *ids = NULL;
439         }
440         RETURN(rc);
441 }
442
443 static void reconstruct_open(struct mds_update_record *rec, int offset,
444                              struct ptlrpc_request *req,
445                              struct lustre_handle *child_lockh)
446 {
447         struct ptlrpc_request *oldreq = req->rq_export->exp_outstanding_reply;
448         struct mds_export_data *med = &req->rq_export->exp_mds_data;
449         struct mds_client_data *mcd = med->med_mcd;
450         struct mds_obd *mds = mds_req2mds(req);
451         struct mds_file_data *mfd;
452         struct obd_device *obd = req->rq_export->exp_obd;
453         struct dentry *parent, *child;
454         struct ldlm_reply *rep;
455         struct mds_body *body;
456         int rc;
457         struct list_head *t;
458         int put_child = 1;
459         ENTRY;
460
461         LASSERT(offset == 2);                  /* only called via intent */
462         rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep));
463         body = lustre_msg_buf(req->rq_repmsg, 1, sizeof (*body));
464
465         /* copy rc, transno and disp; steal locks */
466         mds_req_from_mcd(req, mcd);
467         intent_set_disposition(rep, mcd->mcd_last_data);
468
469         /* Only replay if create or open actually happened. */
470         if (!intent_disposition(rep, DISP_OPEN_CREATE | DISP_OPEN_OPEN) ) {
471                 EXIT;
472                 return; /* error looking up parent or child */
473         }
474
475         parent = mds_fid2dentry(mds, rec->ur_fid1, NULL);
476         LASSERT(!IS_ERR(parent));
477
478         child = ll_lookup_one_len(rec->ur_name, parent, rec->ur_namelen - 1);
479         LASSERT(!IS_ERR(child));
480
481         if (!child->d_inode) {
482                 GOTO(out_dput, 0); /* child not present to open */
483         }
484
485         /* At this point, we know we have a child. We'll send
486          * it back _unless_ it not created and open failed.
487          */
488         if (intent_disposition(rep, DISP_OPEN_OPEN) &&
489             !intent_disposition(rep, DISP_OPEN_CREATE) &&
490             req->rq_status) {
491                 GOTO(out_dput, 0);
492         }
493
494         /* get lock (write for O_CREAT, read otherwise) */
495
496         mds_pack_inode2fid(&body->fid1, child->d_inode);
497         mds_pack_inode2body(body, child->d_inode);
498         if (S_ISREG(child->d_inode->i_mode)) {
499                 rc = mds_pack_md(obd, req->rq_repmsg, 2, body,
500                                  child->d_inode, 1);
501
502                 if (rc)
503                         LASSERT(rc == req->rq_status);
504
505                 /* If we have LOV EA data, the OST holds size, mtime */
506                 if (!(body->valid & OBD_MD_FLEASIZE))
507                         body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
508                                         OBD_MD_FLATIME | OBD_MD_FLMTIME);
509         } else {
510                 /* XXX need to check this case */
511         }
512
513         /* If we're opening a file without an EA, change to a write
514            lock (unless we already have one). */
515
516         /* If we have -EEXIST as the status, and we were asked to create
517          * exclusively, we can tell we failed because the file already existed.
518          */
519         if (req->rq_status == -EEXIST &&
520             ((rec->ur_flags & (MDS_OPEN_CREAT | MDS_OPEN_EXCL)) ==
521              (MDS_OPEN_CREAT | MDS_OPEN_EXCL))) {
522                 GOTO(out_dput, 0);
523         }
524
525         /* If we didn't get as far as trying to open, then some locking thing
526          * probably went wrong, and we'll just bail here.
527          */
528         if (!intent_disposition(rep, DISP_OPEN_OPEN))
529                 GOTO(out_dput, 0);
530
531         /* If we failed, then we must have failed opening, so don't look for
532          * file descriptor or anything, just give the client the bad news.
533          */
534         if (req->rq_status)
535                 GOTO(out_dput, 0);
536
537         mfd = NULL;
538         list_for_each(t, &med->med_open_head) {
539                 mfd = list_entry(t, struct mds_file_data, mfd_list);
540                 if (mfd->mfd_xid == req->rq_xid)
541                         break;
542                 mfd = NULL;
543         }
544
545         if (oldreq != NULL) {
546                 /* if we're not recovering, it had better be found */
547                 LASSERT(mfd != NULL);
548         } else if (mfd == NULL) {
549                 mntget(mds->mds_vfsmnt);
550                 CERROR("Re-opened file \n");
551                 mfd = mds_dentry_open(child, mds->mds_vfsmnt,
552                                       rec->ur_flags & ~MDS_OPEN_TRUNC, req);
553                 if (!mfd) {
554                         CERROR("mds: out of memory\n");
555                         GOTO(out_dput, req->rq_status = -ENOMEM);
556                 }
557                 put_child = 0;
558         }
559
560  out_dput:
561         if (put_child)
562                 l_dput(child);
563         l_dput(parent);
564         EXIT;
565 }
566
567 /* do NOT or the MAY_*'s, you'll get the weakest */
568 static int accmode(int flags)
569 {
570         int res = 0;
571
572         if (flags & FMODE_READ)
573                 res = MAY_READ;
574         if (flags & (FMODE_WRITE|MDS_OPEN_TRUNC))
575                 res |= MAY_WRITE;
576         if (flags & FMODE_EXEC)
577                 res = MAY_EXEC;
578         return res;
579 }
580
581 /* Handles object creation, actual opening, and I/O epoch */
582 static int mds_finish_open(struct ptlrpc_request *req, struct dentry *dchild,
583                            struct mds_body *body, int flags, void **handle,
584                            struct mds_update_record *rec,struct ldlm_reply *rep)
585 {
586         struct mds_obd *mds = mds_req2mds(req);
587         struct obd_device *obd = req->rq_export->exp_obd;
588         struct mds_file_data *mfd = NULL;
589         obd_id *ids = NULL; /* object IDs created */
590         int rc;
591         ENTRY;
592
593         /* atomically create objects if necessary */
594         down(&dchild->d_inode->i_sem);
595         if (S_ISREG(dchild->d_inode->i_mode) &&
596             !(body->valid & OBD_MD_FLEASIZE)) {
597                 rc = mds_pack_md(obd, req->rq_repmsg, 2, body,
598                                  dchild->d_inode, 0);
599                 if (rc) {
600                         up(&dchild->d_inode->i_sem);
601                         RETURN(rc);
602                 }
603         }
604         if (rec != NULL) {
605                 /* no EA: create objects */
606                 rc = mds_create_objects(req, 2, rec, mds, obd,
607                                         dchild->d_inode, handle, &ids);
608                 if (rc) {
609                         CERROR("mds_create_objects: rc = %d\n", rc);
610                         up(&dchild->d_inode->i_sem);
611                         RETURN(rc);
612                 }
613         }
614         /* If the inode has EA data, then OSTs hold size, mtime */
615         if (S_ISREG(dchild->d_inode->i_mode) &&
616             !(body->valid & OBD_MD_FLEASIZE)) {
617                 body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
618                                 OBD_MD_FLATIME | OBD_MD_FLMTIME);
619         }
620         up(&dchild->d_inode->i_sem);
621
622         intent_set_disposition(rep, DISP_OPEN_OPEN);
623         mfd = mds_dentry_open(dchild, mds->mds_vfsmnt, flags, req);
624         if (IS_ERR(mfd))
625                 RETURN(PTR_ERR(mfd));
626
627         CDEBUG(D_INODE, "mfd %p, cookie "LPX64"\n", mfd,
628                mfd->mfd_handle.h_cookie);
629         if (ids != NULL) {
630                 mds_lov_update_objids(obd, ids);
631                 OBD_FREE(ids, sizeof(*ids) * mds->mds_lov_desc.ld_tgt_count);
632         }
633         if (rc)
634                 mds_mfd_destroy(mfd);
635         RETURN(rc);
636 }
637
638 static int mds_open_by_fid(struct ptlrpc_request *req, struct ll_fid *fid,
639                            struct mds_body *body, int flags,
640                            struct mds_update_record *rec,struct ldlm_reply *rep)
641 {
642         struct mds_obd *mds = mds_req2mds(req);
643         struct inode *pending_dir = mds->mds_pending_dir->d_inode;
644         struct dentry *dchild;
645         char fidname[LL_FID_NAMELEN];
646         int fidlen = 0, rc;
647         void *handle = NULL;
648         ENTRY;
649
650         down(&pending_dir->i_sem);
651         fidlen = ll_fid2str(fidname, fid->id, fid->generation);
652         dchild = lookup_one_len(fidname, mds->mds_pending_dir, fidlen);
653         if (IS_ERR(dchild)) {
654                 up(&pending_dir->i_sem);
655                 rc = PTR_ERR(dchild);
656                 CERROR("error looking up %s in PENDING: rc = %d\n",fidname, rc);
657                 RETURN(rc);
658         }
659
660         if (dchild->d_inode != NULL) {
661                 up(&pending_dir->i_sem);
662                 mds_inode_set_orphan(dchild->d_inode);
663                 mds_pack_inode2fid(&body->fid1, dchild->d_inode);
664                 mds_pack_inode2body(body, dchild->d_inode);
665                 intent_set_disposition(rep, DISP_LOOKUP_EXECD);
666                 intent_set_disposition(rep, DISP_LOOKUP_POS);
667                 CWARN("Orphan %s found and opened in PENDING directory\n",
668                        fidname);
669                 goto open;
670         }
671         dput(dchild);
672         up(&pending_dir->i_sem);
673
674         /* We didn't find it in PENDING so it isn't an orphan.  See
675          * if it was a regular inode that was previously created. */
676         dchild = mds_fid2dentry(mds, fid, NULL);
677         if (IS_ERR(dchild))
678                 RETURN(PTR_ERR(dchild));
679
680         mds_pack_inode2fid(&body->fid1, dchild->d_inode);
681         mds_pack_inode2body(body, dchild->d_inode);
682         intent_set_disposition(rep, DISP_LOOKUP_EXECD);
683         intent_set_disposition(rep, DISP_LOOKUP_POS);
684
685  open:
686         rc = mds_finish_open(req, dchild, body, flags, &handle, rec, rep);
687         rc = mds_finish_transno(mds, dchild ? dchild->d_inode : NULL, handle,
688                                 req, rc, rep ? rep->lock_policy_res1 : 0);
689         /* XXX what do we do here if mds_finish_transno itself failed? */
690
691         l_dput(dchild);
692         RETURN(rc);
693 }
694
695 int mds_pin(struct ptlrpc_request *req)
696 {
697         struct obd_device *obd = req->rq_export->exp_obd;
698         struct mds_body *request_body, *reply_body;
699         struct obd_run_ctxt saved;
700         int rc, size = sizeof(*reply_body);
701         ENTRY;
702
703         request_body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*request_body));
704
705         rc = lustre_pack_reply(req, 1, &size, NULL);
706         if (rc)
707                 RETURN(rc);
708         reply_body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply_body));
709
710         push_ctxt(&saved, &obd->obd_ctxt, NULL);
711         rc = mds_open_by_fid(req, &request_body->fid1, reply_body,
712                              request_body->flags, NULL, NULL);
713         pop_ctxt(&saved, &obd->obd_ctxt, NULL);
714
715         RETURN(rc);
716 }
717
718 /*  Get a lock on the ino to sync with creation WRT inode reuse (bug 2029).
719  *  If child_lockh is NULL we just get the lock as a barrier to wait for
720  *  other holders of this lock, and drop it right away again. */
721 int mds_lock_new_child(struct obd_device *obd, struct inode *inode,
722                        struct lustre_handle *child_lockh)
723 {
724         struct ldlm_res_id child_res_id = { .name = { inode->i_ino } };
725         struct lustre_handle lockh;
726         int lock_flags = 0;
727         int rc;
728
729         if (child_lockh == NULL)
730                 child_lockh = &lockh;
731
732         rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, NULL,
733                               child_res_id, LDLM_PLAIN, NULL, 0,
734                               LCK_EX, &lock_flags, ldlm_completion_ast,
735                               mds_blocking_ast, NULL, child_lockh);
736         if (rc != ELDLM_OK)
737                 CERROR("ldlm_cli_enqueue: %d\n", rc);
738         else if (child_lockh == &lockh)
739                 ldlm_lock_decref(child_lockh, LCK_EX);
740
741         return rc;
742 }
743
744 int mds_open(struct mds_update_record *rec, int offset,
745              struct ptlrpc_request *req, struct lustre_handle *child_lockh)
746 {
747         /* XXX ALLOCATE _something_ - 464 bytes on stack here */
748         struct obd_device *obd = req->rq_export->exp_obd;
749         struct mds_obd *mds = mds_req2mds(req);
750         struct ldlm_reply *rep = NULL;
751         struct mds_body *body = NULL;
752         struct dentry *dchild = NULL, *dparent = NULL;
753         struct mds_export_data *med;
754         struct lustre_handle parent_lockh;
755         int rc = 0, cleanup_phase = 0, acc_mode, created = 0;
756         int parent_mode = LCK_PR;
757         void *handle = NULL;
758         struct dentry_params dp;
759         ENTRY;
760
761         if (offset == 2) { /* intent */
762                 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep));
763                 body = lustre_msg_buf(req->rq_repmsg, 1, sizeof (*body));
764         } else if (offset == 0) { /* non-intent reint */
765                 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
766         } else {
767                 body = NULL;
768                 LBUG();
769         }
770
771         MDS_CHECK_RESENT(req, reconstruct_open(rec, offset, req, child_lockh));
772
773         /* Step 0: If we are passed a fid, then we assume the client already
774          * opened this file and is only replaying the RPC, so we open the
775          * inode by fid (at some large expense in security). */
776         if (rec->ur_fid2->id) {
777                 rc = mds_open_by_fid(req, rec->ur_fid2, body, rec->ur_flags,
778                                      rec, rep);
779                 if (rc != -ENOENT)
780                         RETURN(rc);
781                 /* We didn't find the correct inode on disk either, so we
782                  * need to re-create it via a regular replay. */
783                 LASSERT(rec->ur_flags & MDS_OPEN_CREAT);
784         }
785         LASSERT(offset == 2); /* If we got here, we must be called via intent */
786
787         med = &req->rq_export->exp_mds_data;
788         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OPEN_PACK)) {
789                 CERROR("test case OBD_FAIL_MDS_OPEN_PACK\n");
790                 RETURN(-ENOMEM);
791         }
792
793         acc_mode = accmode(rec->ur_flags);
794
795         /* Step 1: Find and lock the parent */
796         if (rec->ur_flags & O_CREAT)
797                 parent_mode = LCK_PW;
798         dparent = mds_fid2locked_dentry(obd, rec->ur_fid1, NULL, parent_mode,
799                                         &parent_lockh, rec->ur_name,
800                                         rec->ur_namelen - 1);
801         if (IS_ERR(dparent)) {
802                 rc = PTR_ERR(dparent);
803                 CERROR("parent lookup error %d\n", rc);
804                 GOTO(cleanup, rc);
805         }
806         LASSERT(dparent->d_inode != NULL);
807
808         cleanup_phase = 1; /* parent dentry and lock */
809
810         /* Step 2: Lookup the child */
811         dchild = ll_lookup_one_len(rec->ur_name, dparent, rec->ur_namelen - 1);
812         if (IS_ERR(dchild))
813                 GOTO(cleanup, rc = PTR_ERR(dchild));
814
815         cleanup_phase = 2; /* child dentry */
816
817         intent_set_disposition(rep, DISP_LOOKUP_EXECD);
818         if (dchild->d_inode)
819                 intent_set_disposition(rep, DISP_LOOKUP_POS);
820         else
821                 intent_set_disposition(rep, DISP_LOOKUP_NEG);
822
823         /*Step 3: If the child was negative, and we're supposed to, create it.*/
824         if (dchild->d_inode == NULL) {
825                 unsigned long ino = rec->ur_fid2->id;
826                 struct iattr iattr;
827                 struct inode *inode;
828
829                 if (!(rec->ur_flags & MDS_OPEN_CREAT)) {
830                         /* It's negative and we weren't supposed to create it */
831                         GOTO(cleanup, rc = -ENOENT);
832                 }
833
834                 intent_set_disposition(rep, DISP_OPEN_CREATE);
835                 handle = fsfilt_start(obd, dparent->d_inode, FSFILT_OP_CREATE,
836                                       NULL);
837                 if (IS_ERR(handle)) {
838                         rc = PTR_ERR(handle);
839                         handle = NULL;
840                         GOTO(cleanup, rc);
841                 }
842                 dchild->d_fsdata = (void *) &dp;
843                 dp.p_ptr = req;
844                 dp.p_inum = ino;
845
846                 rc = ll_vfs_create(dparent->d_inode, dchild, rec->ur_mode,NULL);
847                 if (dchild->d_fsdata == (void *)(unsigned long)ino)
848                         dchild->d_fsdata = NULL;
849
850                 if (rc) {
851                         CDEBUG(D_INODE, "error during create: %d\n", rc);
852                         GOTO(cleanup, rc);
853                 }
854                 inode = dchild->d_inode;
855                 if (ino) {
856                         LASSERT(ino == inode->i_ino);
857                         /* Written as part of setattr */
858                         inode->i_generation = rec->ur_fid2->generation;
859                         CDEBUG(D_HA, "recreated ino %lu with gen %u\n",
860                                inode->i_ino, inode->i_generation);
861                 }
862
863                 created = 1;
864                 LTIME_S(iattr.ia_atime) = rec->ur_time;
865                 LTIME_S(iattr.ia_ctime) = rec->ur_time;
866                 LTIME_S(iattr.ia_mtime) = rec->ur_time;
867
868                 iattr.ia_uid = rec->ur_fsuid;
869                 if (dparent->d_inode->i_mode & S_ISGID)
870                         iattr.ia_gid = dparent->d_inode->i_gid;
871                 else
872                         iattr.ia_gid = rec->ur_fsgid;
873
874                 iattr.ia_valid = ATTR_UID | ATTR_GID | ATTR_ATIME |
875                         ATTR_MTIME | ATTR_CTIME;
876
877                 rc = fsfilt_setattr(obd, dchild, handle, &iattr, 0);
878                 if (rc)
879                         CERROR("error on child setattr: rc = %d\n", rc);
880
881                 iattr.ia_valid = ATTR_MTIME | ATTR_CTIME;
882
883                 rc = fsfilt_setattr(obd, dparent, handle, &iattr, 0);
884                 if (rc)
885                         CERROR("error on parent setattr: rc = %d\n", rc);
886
887                 acc_mode = 0;                  /* Don't check for permissions */
888         }
889
890         LASSERT(!mds_inode_is_orphan(dchild->d_inode));
891
892         mds_pack_inode2fid(&body->fid1, dchild->d_inode);
893         mds_pack_inode2body(body, dchild->d_inode);
894
895         if (S_ISREG(dchild->d_inode->i_mode)) {
896                 /* Check permissions etc */
897                 rc = ll_permission(dchild->d_inode, acc_mode, NULL);
898                 if (rc != 0)
899                         GOTO(cleanup, rc);
900
901                 /* Can't write to a read-only file */
902                 if (IS_RDONLY(dchild->d_inode) && (acc_mode & MAY_WRITE) != 0)
903                         GOTO(cleanup, rc = -EPERM);
904
905                 /* An append-only file must be opened in append mode for
906                  * writing */
907                 if (IS_APPEND(dchild->d_inode) && (acc_mode & MAY_WRITE) != 0 &&
908                     ((rec->ur_flags & MDS_OPEN_APPEND) == 0 ||
909                      (rec->ur_flags & MDS_OPEN_TRUNC) != 0))
910                         GOTO(cleanup, rc = -EPERM);
911         }
912
913         if (!created && (rec->ur_flags & MDS_OPEN_CREAT) &&
914             (rec->ur_flags & MDS_OPEN_EXCL)) {
915                 /* File already exists, we didn't just create it, and we
916                  * were passed O_EXCL; err-or. */
917                 GOTO(cleanup, rc = -EEXIST); // returns a lock to the client
918         }
919
920         /* if we are following a symlink, don't open */
921         if (S_ISLNK(dchild->d_inode->i_mode))
922                 GOTO(cleanup, rc = 0);
923
924         if ((rec->ur_flags & MDS_OPEN_DIRECTORY) &&
925             !S_ISDIR(dchild->d_inode->i_mode))
926                 GOTO(cleanup, rc = -ENOTDIR);
927
928         /* Step 5: mds_open it */
929         rc = mds_finish_open(req, dchild, body, rec->ur_flags, &handle, rec,
930                              rep);
931         GOTO(cleanup, rc);
932
933  cleanup:
934         rc = mds_finish_transno(mds, dchild ? dchild->d_inode : NULL, handle,
935                                 req, rc, rep ? rep->lock_policy_res1 : 0);
936         /* XXX what do we do here if mds_finish_transno itself failed? */
937         if (created)
938                 mds_lock_new_child(obd, dchild->d_inode, NULL);
939
940         switch (cleanup_phase) {
941         case 2:
942                 if (rc && created) {
943                         int err = vfs_unlink(dparent->d_inode, dchild);
944                         if (err) {
945                                 CERROR("unlink(%*s) in error path: %d\n",
946                                        dchild->d_name.len, dchild->d_name.name,
947                                        err);
948                         }
949                 }
950                 l_dput(dchild);
951         case 1:
952                 if (dparent == NULL)
953                         break;
954
955                 l_dput(dparent);
956                 if (rc)
957                         ldlm_lock_decref(&parent_lockh, parent_mode);
958                 else
959                         ldlm_put_lock_into_req(req, &parent_lockh, parent_mode);
960         }
961         if (rc == 0)
962                 atomic_inc(&mds->mds_open_count);
963         RETURN(rc);
964 }
965
966 /* Close a "file descriptor" and possibly unlink an orphan from the
967  * PENDING directory.
968  *
969  * If we are being called from mds_disconnect() because the client has
970  * disappeared, then req == NULL and we do not update last_rcvd because
971  * there is nothing that could be recovered by the client at this stage
972  * (it will not even _have_ an entry in last_rcvd anymore).
973  *
974  * Returns EAGAIN if the client needs to get more data and re-close. */
975 int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd,
976                   struct mds_file_data *mfd, int unlink_orphan)
977 {
978         struct inode *inode = mfd->mfd_dentry->d_inode;
979         char fidname[LL_FID_NAMELEN];
980         int last_orphan, fidlen, rc = 0, cleanup_phase = 0;
981         struct dentry *pending_child = NULL;
982         struct mds_obd *mds = &obd->u.mds;
983         struct inode *pending_dir = mds->mds_pending_dir->d_inode;
984         void *handle = NULL;
985         struct mds_body *request_body, *reply_body;
986         struct dentry_params dp;
987         ENTRY;
988
989         if (req != NULL) {
990                 request_body = lustre_msg_buf(req->rq_reqmsg, 0,
991                                               sizeof(*request_body));
992                 reply_body = lustre_msg_buf(req->rq_repmsg, 0,
993                                             sizeof(*reply_body));
994         }
995
996         fidlen = ll_fid2str(fidname, inode->i_ino, inode->i_generation);
997
998         last_orphan = mds_open_orphan_dec_test(inode) &&
999                 mds_inode_is_orphan(inode);
1000
1001         /* this is half of the actual "close" */
1002         if (mfd->mfd_mode & FMODE_WRITE) {
1003                 rc = mds_put_write_access(mds, inode, request_body,
1004                                           last_orphan && unlink_orphan);
1005         } else if (mfd->mfd_mode & FMODE_EXEC) {
1006                 mds_allow_write_access(inode);
1007         }
1008
1009         if (last_orphan && unlink_orphan) {
1010                 LASSERT(rc == 0); /* mds_put_write_access must have succeeded */
1011
1012                 CWARN("destroying orphan object %s\n", fidname);
1013
1014                 /* Sadly, there is no easy way to save pending_child from
1015                  * mds_reint_unlink() into mfd, so we need to re-lookup,
1016                  * but normally it will still be in the dcache. */
1017                 pending_dir = mds->mds_pending_dir->d_inode;
1018                 down(&pending_dir->i_sem);
1019                 cleanup_phase = 1; /* up(i_sem) when finished */
1020                 pending_child = lookup_one_len(fidname, mds->mds_pending_dir,
1021                                                fidlen);
1022                 if (IS_ERR(pending_child))
1023                         GOTO(cleanup, rc = PTR_ERR(pending_child));
1024                 LASSERT(pending_child->d_inode != NULL);
1025
1026                 cleanup_phase = 2; /* dput(pending_child) when finished */
1027                 handle = fsfilt_start(obd, pending_dir, FSFILT_OP_UNLINK_LOG,
1028                                       NULL);
1029                 if (IS_ERR(handle)) {
1030                         rc = PTR_ERR(handle);
1031                         handle = NULL;
1032                         GOTO(cleanup, rc);
1033                 }
1034
1035 #ifdef ENABLE_ORPHANS
1036                 if (req != NULL &&
1037                     (reply_body->valid & OBD_MD_FLEASIZE) &&
1038                     mds_log_op_unlink(obd, pending_child->d_inode,
1039                                       req->rq_repmsg, 1) > 0) {
1040                         reply_body->valid |= OBD_MD_FLCOOKIE;
1041                 }
1042 #endif
1043                 pending_child->d_fsdata = (void *) &dp;
1044                 dp.p_inum = 0;
1045                 dp.p_ptr = req;
1046                 if (S_ISDIR(pending_child->d_inode->i_mode))
1047                         rc = vfs_rmdir(pending_dir, pending_child);
1048                 else
1049                         rc = vfs_unlink(pending_dir, pending_child);
1050                 if (rc)
1051                         CERROR("error unlinking orphan %s: rc %d\n",fidname,rc);
1052         } else if (mfd->mfd_mode & FMODE_WRITE && rc == 0) {
1053                 /* Update the on-disk attributes if this was the last write
1054                  * close, and all information was provided (i.e., rc == 0)
1055                  *
1056                  * XXX this should probably be abstracted with mds_reint_setattr
1057                  */
1058 #if 0
1059                 struct iattr iattr;
1060
1061                 /* XXX can't set block count with fsfilt_setattr (!) */
1062                 iattr.ia_valid = ATTR_CTIME | ATTR_ATIME |
1063                         ATTR_MTIME | ATTR_SIZE;
1064                 iattr.ia_atime = request_body->atime;
1065                 iattr.ia_ctime = request_body->ctime;
1066                 iattr.ia_mtime = request_body->mtime;
1067                 iattr.ia_size = request_body->size;
1068                 /* iattr.ia_blocks = request_body->blocks */
1069
1070                 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
1071                 if (IS_ERR(handle))
1072                         GOTO(cleanup, rc = PTR_ERR(handle));
1073                 rc = fsfilt_setattr(obd, mfd->mfd_dentry, handle, &iattr, 0);
1074                 if (rc)
1075                         CERROR("error in setattr(%s): rc %d\n", fidname, rc);
1076 #endif
1077         }
1078         l_dput(mfd->mfd_dentry);
1079         mds_mfd_destroy(mfd);
1080
1081  cleanup:
1082         atomic_dec(&mds->mds_open_count);
1083         if (req) {
1084                 rc = mds_finish_transno(mds, pending_dir, handle, req, rc, 0);
1085         } else if (handle) {
1086                 int err = fsfilt_commit(obd, pending_dir, handle, 0);
1087                 if (err) {
1088                         CERROR("error committing close: %d\n", err);
1089                         if (!rc)
1090                                 rc = err;
1091                 }
1092         }
1093
1094         switch (cleanup_phase) {
1095         case 2:
1096                 dput(pending_child);
1097         case 1:
1098                 up(&pending_dir->i_sem);
1099         }
1100         RETURN(rc);
1101 }
1102
1103 int mds_close(struct ptlrpc_request *req)
1104 {
1105         struct mds_export_data *med = &req->rq_export->exp_mds_data;
1106         struct obd_device *obd = req->rq_export->exp_obd;
1107         struct mds_body *body;
1108         struct mds_file_data *mfd;
1109         struct obd_run_ctxt saved;
1110         struct inode *inode;
1111         int rc, repsize[3] = {sizeof(struct mds_body),
1112                               obd->u.mds.mds_max_mdsize,
1113                               obd->u.mds.mds_max_cookiesize};
1114         ENTRY;
1115
1116         MDS_CHECK_RESENT(req, mds_reconstruct_generic(req));
1117
1118         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
1119         if (body == NULL) {
1120                 CERROR("Can't unpack body\n");
1121                 req->rq_status = -EFAULT;
1122                 RETURN(-EFAULT);
1123         }
1124
1125         if (body->flags & MDS_BFLAG_UNCOMMITTED_WRITES)
1126                 /* do some stuff */ ;
1127
1128         mfd = mds_handle2mfd(&body->handle);
1129         if (mfd == NULL) {
1130                 DEBUG_REQ(D_ERROR, req, "no handle for file close ino "LPD64
1131                           ": cookie "LPX64, body->fid1.id, body->handle.cookie);
1132                 req->rq_status = -ESTALE;
1133                 RETURN(-ESTALE);
1134         }
1135
1136         rc = lustre_pack_reply(req, 3, repsize, NULL);
1137         if (rc) {
1138                 CERROR("lustre_pack_reply: rc = %d\n", rc);
1139                 req->rq_status = rc;
1140         }
1141
1142         inode = mfd->mfd_dentry->d_inode;
1143         if (mds_inode_is_orphan(inode) && mds_open_orphan_count(inode) == 1) {
1144                 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
1145                 LASSERT(body != NULL);
1146
1147                 mds_pack_inode2fid(&body->fid1, inode);
1148                 mds_pack_inode2body(body, inode);
1149                 mds_pack_md(obd, req->rq_repmsg, 1, body, inode, 1);
1150         }
1151         spin_lock(&med->med_open_lock);
1152         list_del(&mfd->mfd_list);
1153         spin_unlock(&med->med_open_lock);
1154
1155         push_ctxt(&saved, &obd->obd_ctxt, NULL);
1156         req->rq_status = mds_mfd_close(rc ? NULL : req, obd, mfd, 1);
1157         pop_ctxt(&saved, &obd->obd_ctxt, NULL);
1158
1159         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_PACK)) {
1160                 CERROR("test case OBD_FAIL_MDS_CLOSE_PACK\n");
1161                 req->rq_status = -ENOMEM;
1162                 mds_mfd_put(mfd);
1163                 RETURN(-ENOMEM);
1164         }
1165
1166         mds_mfd_put(mfd);
1167         RETURN(0);
1168 }
1169
1170 int mds_done_writing(struct ptlrpc_request *req)
1171 {
1172         struct mds_body *body;
1173         int rc, size = sizeof(struct mds_body);
1174         ENTRY;
1175
1176         MDS_CHECK_RESENT(req, mds_reconstruct_generic(req));
1177
1178         body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
1179         if (body == NULL) {
1180                 CERROR("Can't unpack body\n");
1181                 req->rq_status = -EFAULT;
1182                 RETURN(-EFAULT);
1183         }
1184
1185         rc = lustre_pack_reply(req, 1, &size, NULL);
1186         if (rc) {
1187                 CERROR("lustre_pack_reply: rc = %d\n", rc);
1188                 req->rq_status = rc;
1189         }
1190
1191         RETURN(0);
1192 }