Whamcloud - gitweb
more req-layout cleanups (for intents and reints)
[fs/lustre-release.git] / lustre / mdt / mdt_lib.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/mdt/mdt_lib.c
5  *  Lustre Metadata Target (mdt) request unpacking helper.
6  *
7  *  Copyright (c) 2006 Cluster File Systems, Inc.
8  *   Author: Peter Braam <braam@clusterfs.com>
9  *   Author: Andreas Dilger <adilger@clusterfs.com>
10  *   Author: Phil Schwan <phil@clusterfs.com>
11  *   Author: Mike Shaver <shaver@clusterfs.com>
12  *   Author: Nikita Danilov <nikita@clusterfs.com>
13  *   Author: Huang Hua <huanghua@clusterfs.com>
14  *
15  *
16  *   This file is part of the Lustre file system, http://www.lustre.org
17  *   Lustre is a trademark of Cluster File Systems, Inc.
18  *
19  *   You may have signed or agreed to another license before downloading
20  *   this software.  If so, you are bound by the terms and conditions
21  *   of that agreement, and the following does not apply to you.  See the
22  *   LICENSE file included with this distribution for more information.
23  *
24  *   If you did not agree to a different license, then this copy of Lustre
25  *   is open source software; you can redistribute it and/or modify it
26  *   under the terms of version 2 of the GNU General Public License as
27  *   published by the Free Software Foundation.
28  *
29  *   In either case, Lustre is distributed in the hope that it will be
30  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
31  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  *   license text for more details.
33  */
34
35
36 #ifndef EXPORT_SYMTAB
37 # define EXPORT_SYMTAB
38 #endif
39 #define DEBUG_SUBSYSTEM S_MDS
40
41 #include "mdt_internal.h"
42
43
44 /* unpacking */
45 static int mdt_setattr_unpack(struct mdt_thread_info *info)
46 {
47         ENTRY;
48         RETURN(-EOPNOTSUPP);
49 }
50
51 static int mdt_create_unpack(struct mdt_thread_info *info)
52 {
53         struct mdt_rec_create *rec;
54         struct lu_attr *attr = &info->mti_attr;
55         struct mdt_reint_record *rr = &info->mti_rr;
56         struct req_capsule *pill = &info->mti_pill;
57         int result;
58         ENTRY;
59
60         rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
61         if (rec != NULL) {
62                 rr->rr_fid1 = &rec->cr_fid1;
63                 rr->rr_fid2 = &rec->cr_fid2;
64                 attr->la_mode = rec->cr_mode;
65
66                 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
67                 result = 0;
68         } else
69                 result = -EFAULT;
70         RETURN(result);
71 }
72
73 static int mdt_link_unpack(struct mdt_thread_info *info)
74 {
75         ENTRY;
76         RETURN(-EOPNOTSUPP);
77 }
78
79 static int mdt_unlink_unpack(struct mdt_thread_info *info)
80 {
81         ENTRY;
82         RETURN(-EOPNOTSUPP);
83 }
84
85 static int mdt_rename_unpack(struct mdt_thread_info *info)
86 {
87         ENTRY;
88         RETURN(-EOPNOTSUPP);
89 }
90
91 static int mdt_open_unpack(struct mdt_thread_info *info)
92 {
93         struct mdt_rec_create   *rec;
94         struct lu_attr          *attr = &info->mti_attr;
95         struct req_capsule      *pill = &info->mti_pill;
96         struct mdt_reint_record *rr   = &info->mti_rr;
97         int result;
98         ENTRY;
99
100         rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
101         if (rec != NULL) {
102                 rr->rr_fid1   = &rec->cr_fid1;
103                 rr->rr_fid2   = &rec->cr_fid2;
104                 attr->la_mode = rec->cr_mode;
105                 rr->rr_flags  = rec->cr_flags;
106
107                 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
108                 if (rr->rr_name == NULL)
109                         result = -EFAULT;
110                 else
111                         result = 0;
112         } else
113                 result = -EFAULT;
114
115         RETURN(result);
116 }
117
118 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
119
120 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
121         [REINT_SETATTR]  = mdt_setattr_unpack,
122         [REINT_CREATE]   = mdt_create_unpack,
123         [REINT_LINK]     = mdt_link_unpack,
124         [REINT_UNLINK]   = mdt_unlink_unpack,
125         [REINT_RENAME]   = mdt_rename_unpack,
126         [REINT_OPEN]     = mdt_open_unpack
127 };
128
129 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
130 {
131         int rc;
132
133         ENTRY;
134
135         if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
136                 info->mti_rr.rr_opcode = op;
137                 rc = mdt_reint_unpackers[op](info);
138         } else {
139                 CERROR("Unexpected opcode %d\n", op);
140                 rc = -EFAULT;
141         }
142         RETURN(rc);
143 }