Whamcloud - gitweb
LU-7991 quota: project quota against ZFS backend
[fs/lustre-release.git] / lustre / include / obj_update.h
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  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2014, Intel Corporation.
27  *
28  * Selection of object_update and object_update_param handling functions
29  */
30
31 #ifndef _OBJ_UPDATE_H_
32 #define _OBJ_UPDATE_H_
33
34 #include <uapi/linux/lustre/lustre_idl.h>
35
36 static inline size_t
37 object_update_param_size(const struct object_update_param *param)
38 {
39         return cfs_size_round(sizeof(*param) + param->oup_len);
40 }
41
42 static inline size_t
43 object_update_params_size(const struct object_update *update)
44 {
45         const struct object_update_param *param;
46         size_t                           total_size = 0;
47         unsigned int                     i;
48
49         param = &update->ou_params[0];
50         for (i = 0; i < update->ou_params_count; i++) {
51                 size_t size = object_update_param_size(param);
52
53                 param = (struct object_update_param *)((char *)param + size);
54                 total_size += size;
55         }
56
57         return total_size;
58 }
59
60 static inline size_t
61 object_update_size(const struct object_update *update)
62 {
63         return offsetof(struct object_update, ou_params[0]) +
64                object_update_params_size(update);
65 }
66
67 static inline struct object_update *
68 object_update_request_get(const struct object_update_request *our,
69                           unsigned int index, size_t *size)
70 {
71         void    *ptr;
72         unsigned int i;
73
74         if (index >= our->ourq_count)
75                 return NULL;
76
77         ptr = (void *)&our->ourq_updates[0];
78         for (i = 0; i < index; i++)
79                 ptr += object_update_size(ptr);
80
81         if (size != NULL)
82                 *size = object_update_size(ptr);
83
84         return ptr;
85 }
86
87
88
89 static inline struct object_update_result *
90 object_update_result_get(const struct object_update_reply *reply,
91                          unsigned int index, size_t *size)
92 {
93         __u16 count = reply->ourp_count;
94         unsigned int i;
95         void *ptr;
96
97         if (index >= count)
98                 return NULL;
99
100         ptr = (char *)reply +
101               cfs_size_round(offsetof(struct object_update_reply,
102                                       ourp_lens[count]));
103         for (i = 0; i < index; i++) {
104                 if (reply->ourp_lens[i] == 0)
105                         return NULL;
106
107                 ptr += cfs_size_round(reply->ourp_lens[i]);
108         }
109
110         if (size != NULL)
111                 *size = reply->ourp_lens[index];
112
113         return ptr;
114 }
115 #endif