]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/lib/test_env.c
4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 spdk_malloc(size_t size
, size_t align
, uint64_t *phys_addr
)
45 if (posix_memalign(&buf
, align
, size
)) {
49 *phys_addr
= (uint64_t)buf
;
55 spdk_zmalloc(size_t size
, size_t align
, uint64_t *phys_addr
)
57 void *buf
= spdk_malloc(size
, align
, phys_addr
);
66 spdk_realloc(void *buf
, size_t size
, size_t align
, uint64_t *phys_addr
)
68 return realloc(buf
, size
);
71 void spdk_free(void *buf
)
76 bool ut_fail_vtophys
= false;
77 uint64_t spdk_vtophys(void *buf
)
79 if (ut_fail_vtophys
) {
80 return (uint64_t) - 1;
82 return (uintptr_t)buf
;
87 spdk_memzone_reserve(const char *name
, size_t len
, int socket_id
, unsigned flags
)
93 spdk_memzone_lookup(const char *name
)
99 spdk_memzone_dump(FILE *f
)
105 spdk_memzone_free(const char *name
)
110 struct spdk_mempool
*
111 spdk_mempool_create(const char *name
, size_t count
,
112 size_t ele_size
, size_t cache_size
, int socket_id
)
116 return (struct spdk_mempool
*)&mp
;
120 spdk_mempool_free(struct spdk_mempool
*mp
)
126 spdk_mempool_get(struct spdk_mempool
*mp
)
130 if (posix_memalign(&buf
, 64, 0x1000)) {
138 spdk_mempool_put(struct spdk_mempool
*mp
, void *ele
)
144 spdk_process_is_primary(void)
150 uint64_t spdk_get_ticks(void)
155 uint64_t spdk_get_ticks_hz(void)
161 spdk_pci_addr_parse(struct spdk_pci_addr
*addr
, const char *bdf
)
163 unsigned domain
, bus
, dev
, func
;
165 if (addr
== NULL
|| bdf
== NULL
) {
169 if (sscanf(bdf
, "%x:%x:%x.%x", &domain
, &bus
, &dev
, &func
) == 4) {
170 /* Matched a full address - all variables are initialized */
171 } else if (sscanf(bdf
, "%x:%x:%x", &domain
, &bus
, &dev
) == 3) {
173 } else if (sscanf(bdf
, "%x:%x.%x", &bus
, &dev
, &func
) == 3) {
175 } else if (sscanf(bdf
, "%x:%x", &bus
, &dev
) == 2) {
182 if (domain
> 0xFFFF || bus
> 0xFF || dev
> 0x1F || func
> 7) {
186 addr
->domain
= domain
;
195 spdk_pci_addr_fmt(char *bdf
, size_t sz
, const struct spdk_pci_addr
*addr
)
199 rc
= snprintf(bdf
, sz
, "%04x:%02x:%02x.%x",
200 addr
->domain
, addr
->bus
,
201 addr
->dev
, addr
->func
);
203 if (rc
> 0 && (size_t)rc
< sz
) {