Skip to content

Commit 36cc99d

Browse files
committed
make zero_filled function required
1 parent d48630f commit 36cc99d

File tree

7 files changed

+36
-37
lines changed

7 files changed

+36
-37
lines changed

examples/providers/common.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ dpusm_provider_copy_to_generic(dpusm_mv_t *mv, void *buf, size_t size) {
122122
return DPUSM_OK;
123123
}
124124

125+
int dpusm_zero_fill(void *handle, size_t offset, size_t size) {
126+
alloc_t *alloc = (alloc_t *) handle;
127+
if (!alloc) {
128+
return DPUSM_ERROR;
129+
}
130+
131+
/* would go past buffer */
132+
if (alloc->size <= (offset + size)) {
133+
return DPUSM_ERROR;
134+
}
135+
136+
void *ptr = ptr_offset(alloc->ptr, offset);
137+
memset(ptr, 0, size);
138+
139+
return DPUSM_OK;
140+
}
141+
125142
const dpusm_pf_t example_dpusm_provider_functions = {
126143
.algorithms = dpusm_provider_algorithms,
127144
.alloc = dpusm_provider_alloc,
@@ -140,10 +157,10 @@ const dpusm_pf_t example_dpusm_provider_functions = {
140157
.scatterlist = NULL,
141158
},
142159
},
160+
.zero_fill = dpusm_zero_fill,
143161
.at_connect = NULL,
144162
.at_disconnect = NULL,
145163
.mem_stats = NULL,
146-
.zero_fill = NULL,
147164
.all_zeros = NULL,
148165
.compress = NULL,
149166
.decompress = NULL,

examples/providers/common.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33

44
#include <dpusm/provider_api.h>
55

6-
/* required functions */
7-
int dpusm_provider_algorithms(int *compress, int *decompress,
8-
int *checksum, int *checksum_byteorder,
9-
int *raid);
10-
void *dpusm_provider_alloc(size_t size);
11-
void *dpusm_provider_ref(void *src, size_t offset, size_t size);
12-
void dpusm_provider_free(void *handle);
13-
int dpusm_provider_copy_from_mem(dpusm_mv_t *mv, const void *buf, size_t size);
14-
int dpusm_provider_copy_to_mem(dpusm_mv_t *mv, void *buf, size_t size);
15-
166
/* filled callback struct */
177
extern const dpusm_pf_t example_dpusm_provider_functions;
188

include/dpusm/common.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ typedef enum {
2121
DPUSM_OPTIONAL_COPY_FROM_SCATTERLIST = 1 << 2,
2222
DPUSM_OPTIONAL_COPY_TO_SCATTERLIST = 1 << 3,
2323
DPUSM_OPTIONAL_MEM_STATS = 1 << 4,
24-
DPUSM_OPTIONAL_ZERO_FILL = 1 << 5,
25-
DPUSM_OPTIONAL_ALL_ZEROS = 1 << 6,
24+
DPUSM_OPTIONAL_ALL_ZEROS = 1 << 5,
2625

27-
DPUSM_OPTIONAL_MAX = 1 << 5,
26+
DPUSM_OPTIONAL_MAX = 1 << 6,
2827
} dpusm_optional_t;
2928

3029
extern const char *DPUSM_OPTIONAL_STR[];

include/dpusm/provider_api.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ typedef struct dpusm_provider_functions {
7777
} to;
7878
} copy;
7979

80+
/* fill in a buffer with zeros */
81+
int (*zero_fill)(void *handle, size_t offset, size_t size);
82+
8083
/*
8184
* optional
8285
*/
@@ -111,9 +114,6 @@ typedef struct dpusm_provider_functions {
111114
int (*mem_stats)(size_t *t_count, size_t *t_size, size_t *t_actual,
112115
size_t *a_count, size_t *a_size, size_t *a_actual);
113116

114-
/* fill in a buffer with zeros */
115-
int (*zero_fill)(void *handle, size_t offset, size_t size);
116-
117117
/* whether or not a buffer is all zeros */
118118
int (*all_zeros)(void *handle, size_t offset, size_t size);
119119

include/dpusm/user_api.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ typedef struct dpusm_user_functions {
9292
} to;
9393
} copy;
9494

95+
/* fill in a buffer with zeros */
96+
int (*zero_fill)(void *handle, size_t offset, size_t size);
97+
9598
/*
9699
* optional
97100
*/
@@ -111,9 +114,6 @@ typedef struct dpusm_user_functions {
111114
size_t *t_count, size_t *t_size, size_t *t_actual,
112115
size_t *a_count, size_t *a_size, size_t *a_actual);
113116

114-
/* fill in a buffer with zeros */
115-
int (*zero_fill)(void *handle, size_t offset, size_t size);
116-
117117
/* whether or not a buffer is all zeros */
118118
int (*all_zeros)(void *handle, size_t offset, size_t size);
119119

src/provider.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ dpusm_provider_sane_at_load(const dpusm_pf_t *funcs)
3838
!!funcs->get_size +
3939
!!funcs->free +
4040
!!funcs->copy.from.generic +
41-
!!funcs->copy.to.generic);
41+
!!funcs->copy.to.generic +
42+
!!funcs->zero_fill);
4243

4344
const int raid_gen = (
4445
!!funcs->raid.can_compute +
@@ -65,7 +66,7 @@ dpusm_provider_sane_at_load(const dpusm_pf_t *funcs)
6566

6667
// get bitmap of bad function groups
6768
const int rc = (
68-
(!(required == 7)?DPUSM_PROVIDER_BAD_GROUP_REQUIRED:0) |
69+
(!(required == 8)?DPUSM_PROVIDER_BAD_GROUP_REQUIRED:0) |
6970
(!((raid_gen == 0) || (raid_gen == 5))?DPUSM_PROVIDER_BAD_GROUP_RAID_GEN:0) |
7071
(!((raid_rec == 0) || ((raid_gen == 5) && (raid_rec == 2)))?DPUSM_PROVIDER_BAD_GROUP_RAID_REC:0) |
7172
(!((file == 0) || (file == 3))?DPUSM_PROVIDER_BAD_GROUP_FILE:0) |
@@ -139,11 +140,6 @@ dpusmph_init(struct module *module, const dpusm_pf_t *funcs)
139140
print_supported(name, enum2str(DPUSM_OPTIONAL_STR, DPUSM_OPTIONAL_MEM_STATS));
140141
}
141142

142-
if (funcs->zero_fill) {
143-
dpusmph->capabilities.optional |= DPUSM_OPTIONAL_ZERO_FILL;
144-
print_supported(name, enum2str(DPUSM_OPTIONAL_STR, DPUSM_OPTIONAL_ZERO_FILL));
145-
}
146-
147143
if (funcs->all_zeros) {
148144
dpusmph->capabilities.optional |= DPUSM_OPTIONAL_ALL_ZEROS;
149145
print_supported(name, enum2str(DPUSM_OPTIONAL_STR, DPUSM_OPTIONAL_ALL_ZEROS));

src/user.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ dpusm_copy_to_scatterlist(dpusm_mv_t *mv,
353353
sgl, nents, size);
354354
}
355355

356+
static int
357+
dpusm_zero_fill(void *handle, size_t offset, size_t size) {
358+
CHECK_HANDLE(handle, dpusmh, DPUSM_ERROR);
359+
return FUNCS(dpusmh->provider)->zero_fill(dpusmh->handle, offset, size);
360+
}
361+
356362
static int
357363
dpusm_provider_mem_stats(void *provider,
358364
size_t *t_count, size_t *t_size, size_t *t_actual,
@@ -365,15 +371,6 @@ dpusm_provider_mem_stats(void *provider,
365371
a_count, a_size, a_actual);
366372
}
367373

368-
static int
369-
dpusm_zero_fill(void *handle, size_t offset, size_t size) {
370-
CHECK_HANDLE(handle, dpusmh, DPUSM_ERROR);
371-
if (!FUNCS(dpusmh->provider)->zero_fill) {
372-
return DPUSM_NOT_IMPLEMENTED;
373-
}
374-
return FUNCS(dpusmh->provider)->zero_fill(dpusmh->handle, offset, size);
375-
}
376-
377374
static int
378375
dpusm_all_zeros(void *handle, size_t offset, size_t size) {
379376
CHECK_HANDLE(handle, dpusmh, DPUSM_ERROR);
@@ -702,8 +699,8 @@ static const dpusm_uf_t user_functions = {
702699
.scatterlist = dpusm_copy_to_scatterlist,
703700
},
704701
},
705-
.mem_stats = dpusm_provider_mem_stats,
706702
.zero_fill = dpusm_zero_fill,
703+
.mem_stats = dpusm_provider_mem_stats,
707704
.all_zeros = dpusm_all_zeros,
708705
.compress = dpusm_compress,
709706
.decompress = dpusm_decompress,

0 commit comments

Comments
 (0)