]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/src/utils/utils_device.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / ocf / src / utils / utils_device.h
1 /*
2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
4 */
5
6 #ifndef UTILS_DEVICE_H_
7 #define UTILS_DEVICE_H_
8
9 static inline int _ocf_uuid_set(const struct ocf_volume_uuid *uuid,
10 struct ocf_metadata_uuid *muuid)
11 {
12 int result;
13
14 if (!uuid || !muuid) {
15 return -EINVAL;
16 }
17
18 if (!uuid->data || !muuid->data) {
19 return -EINVAL;
20 }
21
22 if (uuid->size > sizeof(muuid->data)) {
23 return -ENOBUFS;
24 }
25
26 result = env_memcpy(muuid->data, sizeof(muuid->data), uuid->data, uuid->size);
27 if (result)
28 return result;
29 result = env_memset(muuid->data + uuid->size,
30 sizeof(muuid->data) - uuid->size, 0);
31 if (result)
32 return result;
33 muuid->size = uuid->size;
34
35 return 0;
36 }
37
38 static inline int ocf_metadata_set_core_uuid(ocf_core_t core,
39 const struct ocf_volume_uuid *uuid,
40 struct ocf_volume_uuid *new_uuid)
41 {
42 ocf_cache_t cache = ocf_core_get_cache(core);
43 struct ocf_metadata_uuid *muuid = ocf_metadata_get_core_uuid(cache,
44 ocf_core_get_id(core));
45
46 if (_ocf_uuid_set(uuid, muuid))
47 return -ENOBUFS;
48
49 if (new_uuid) {
50 new_uuid->data = muuid->data;
51 new_uuid->size = muuid->size;
52 }
53
54 return 0;
55 }
56
57 static inline void ocf_metadata_clear_core_uuid(ocf_core_t core)
58 {
59 struct ocf_volume_uuid uuid = { .size = 0, };
60
61 ocf_metadata_set_core_uuid(core, &uuid, NULL);
62 }
63
64 #endif /* UTILS_MEM_H_ */