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