Whamcloud - gitweb
LU-17307 mdt: get dirent count by request
[fs/lustre-release.git] / lustre / ptlrpc / pack_server.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * GPL HEADER END
17  */
18 /*
19  * Copyright (c) 2011, 2017, Intel Corporation.
20  */
21 /*
22  * This file is part of Lustre, http://www.lustre.org/
23  *
24  * lustre/ptlrpc/pack_server.c
25  *
26  * (Un)packing of OST requests
27  *
28  */
29
30 #define DEBUG_SUBSYSTEM S_RPC
31
32 #include <lustre_swab.h>
33 #include <llog_swab.h>
34 #include <obd_class.h>
35
36 void lustre_swab_object_update(struct object_update *ou)
37 {
38         struct object_update_param *param;
39         size_t  i;
40
41         __swab16s(&ou->ou_type);
42         __swab16s(&ou->ou_params_count);
43         __swab32s(&ou->ou_result_size);
44         __swab32s(&ou->ou_flags);
45         __swab32s(&ou->ou_padding1);
46         __swab64s(&ou->ou_batchid);
47         lustre_swab_lu_fid(&ou->ou_fid);
48         param = &ou->ou_params[0];
49         for (i = 0; i < ou->ou_params_count; i++) {
50                 __swab16s(&param->oup_len);
51                 __swab16s(&param->oup_padding);
52                 __swab32s(&param->oup_padding2);
53                 param = (struct object_update_param *)((char *)param +
54                          object_update_param_size(param));
55         }
56 }
57 int lustre_swab_object_update_request(struct object_update_request *our,
58                                       __u32 len)
59 {
60         __u32 i, size = 0;
61         struct object_update *ou;
62
63         __swab32s(&our->ourq_magic);
64         __swab16s(&our->ourq_count);
65         __swab16s(&our->ourq_padding);
66
67         /* Don't need to calculate request size if len is 0. */
68         if (len > 0) {
69                 size = sizeof(struct object_update_request);
70                 for (i = 0; i < our->ourq_count; i++) {
71                         ou = object_update_request_get(our, i, NULL);
72                         if (ou == NULL)
73                                 return -EPROTO;
74                         size += sizeof(struct object_update) +
75                                 ou->ou_params_count *
76                                 sizeof(struct object_update_param);
77                 }
78                 if (unlikely(size > len))
79                         return -EOVERFLOW;
80         }
81
82         for (i = 0; i < our->ourq_count; i++) {
83                 ou = object_update_request_get(our, i, NULL);
84                 lustre_swab_object_update(ou);
85         }
86
87         return size;
88 }
89
90 static void
91 lustre_swab_object_update_result_no_len(struct object_update_result *our)
92 {
93         __swab32s(&our->our_rc);
94         __swab16s(&our->our_datalen);
95         __swab16s(&our->our_padding);
96 }
97
98 int lustre_swab_object_update_reply(struct object_update_reply *our, __u32 len)
99 {
100         __u32 i, size;
101
102         __swab32s(&our->ourp_magic);
103         __swab16s(&our->ourp_count);
104         __swab16s(&our->ourp_padding);
105
106         size = sizeof(struct object_update_reply) + our->ourp_count *
107                (sizeof(__u16) + sizeof(struct object_update_result));
108         if (unlikely(size > len))
109                 return -EOVERFLOW;
110
111         for (i = 0; i < our->ourp_count; i++) {
112                 struct object_update_result *ourp;
113
114                 __swab16s(&our->ourp_lens[i]);
115                 ourp = object_update_result_get(our, i, NULL);
116                 if (ourp == NULL)
117                         return -EPROTO;
118                 lustre_swab_object_update_result_no_len(ourp);
119         }
120
121         return size;
122 }
123
124 void lustre_swab_out_update_header(struct out_update_header *ouh)
125 {
126         __swab32s(&ouh->ouh_magic);
127         __swab32s(&ouh->ouh_count);
128         __swab32s(&ouh->ouh_inline_length);
129         __swab32s(&ouh->ouh_reply_size);
130 }
131 EXPORT_SYMBOL(lustre_swab_out_update_header);
132
133 void lustre_swab_out_update_buffer(struct out_update_buffer *oub)
134 {
135         __swab32s(&oub->oub_size);
136         __swab32s(&oub->oub_padding);
137 }
138 EXPORT_SYMBOL(lustre_swab_out_update_buffer);