Whamcloud - gitweb
LU-12567 ptlrpc: handle reply and resend reorder
[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 <llog_swab.h>
33 #include <obd_class.h>
34
35 void lustre_swab_object_update(struct object_update *ou)
36 {
37         struct object_update_param *param;
38         size_t  i;
39
40         __swab16s(&ou->ou_type);
41         __swab16s(&ou->ou_params_count);
42         __swab32s(&ou->ou_result_size);
43         __swab32s(&ou->ou_flags);
44         __swab32s(&ou->ou_padding1);
45         __swab64s(&ou->ou_batchid);
46         lustre_swab_lu_fid(&ou->ou_fid);
47         param = &ou->ou_params[0];
48         for (i = 0; i < ou->ou_params_count; i++) {
49                 __swab16s(&param->oup_len);
50                 __swab16s(&param->oup_padding);
51                 __swab32s(&param->oup_padding2);
52                 param = (struct object_update_param *)((char *)param +
53                          object_update_param_size(param));
54         }
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 void lustre_swab_object_update_result(struct object_update_result *our)
91 {
92         __swab32s(&our->our_rc);
93         __swab16s(&our->our_datalen);
94         __swab16s(&our->our_padding);
95 }
96
97 int lustre_swab_object_update_reply(struct object_update_reply *our, __u32 len)
98 {
99         __u32 i, size;
100
101         __swab32s(&our->ourp_magic);
102         __swab16s(&our->ourp_count);
103         __swab16s(&our->ourp_padding);
104
105         size = sizeof(struct object_update_reply) + our->ourp_count *
106                (sizeof(__u16) + sizeof(struct object_update_result));
107         if (unlikely(size > len))
108                 return -EOVERFLOW;
109
110         for (i = 0; i < our->ourp_count; i++) {
111                 struct object_update_result *ourp;
112
113                 __swab16s(&our->ourp_lens[i]);
114                 ourp = object_update_result_get(our, i, NULL);
115                 if (ourp == NULL)
116                         return -EPROTO;
117                 lustre_swab_object_update_result(ourp);
118         }
119
120         return size;
121 }
122
123 void lustre_swab_out_update_header(struct out_update_header *ouh)
124 {
125         __swab32s(&ouh->ouh_magic);
126         __swab32s(&ouh->ouh_count);
127         __swab32s(&ouh->ouh_inline_length);
128         __swab32s(&ouh->ouh_reply_size);
129 }
130 EXPORT_SYMBOL(lustre_swab_out_update_header);
131
132 void lustre_swab_out_update_buffer(struct out_update_buffer *oub)
133 {
134         __swab32s(&oub->oub_size);
135         __swab32s(&oub->oub_padding);
136 }
137 EXPORT_SYMBOL(lustre_swab_out_update_buffer);