| 229 | } |
| 230 | |
| 231 | static void *fstdump_thread(void *arg) |
| 232 | { |
| 233 | fstdump_per_thread_t *fstdump = (fstdump_per_thread_t *)arg; |
| 234 | fstdump_t *common = fstdump->common; |
| 235 | void *ret = NULL; |
| 236 | void *sendrec; |
| 237 | void *databuf; |
| 238 | size_t buffer_length; |
| 239 | bdb_state_type *bdb_state = common->bdb_state; |
| 240 | |
| 241 | /*thread_started("bdb fstdump");*/ |
| 242 | |
| 243 | /* work out how large a buffer we need. It must be a multiple of 1KB, |
| 244 | * larger than the page size and unsigned int aligned |
| 245 | * (see berkdb docs). */ |
| 246 | buffer_length = bdb_state->attr->fstdump_buffer_length; |
| 247 | if ((buffer_length & (1024 - 1)) != 0) |
| 248 | buffer_length &= ~(1024 - 1); |
| 249 | if (buffer_length < bdb_state->attr->pagesizedta) |
| 250 | buffer_length = bdb_state->attr->pagesizedta; |
| 251 | |
| 252 | sendrec = mymalloc(common->sendrecsz); |
| 253 | if (!sendrec) |
| 254 | logmsg(LOGMSG_ERROR, "fstdump_thread: mymalloc %zu failed (sendrec)\n", |
| 255 | common->sendrecsz); |
| 256 | databuf = mymalloc(buffer_length); |
| 257 | if (!databuf) |
| 258 | logmsg(LOGMSG_ERROR, "fstdump_thread: mymalloc %u failed (databuf)\n", |
| 259 | (unsigned)buffer_length); |
| 260 | |
| 261 | if (sendrec && databuf) { |
| 262 | /* If not threaded then read lock etc already acquired */ |
| 263 | if (fstdump->real_thread) { |
| 264 | bdb_thread_event(common->bdb_state, BDBTHR_EVENT_START_RDONLY); |
| 265 | BDB_READLOCK("fstdump_thread"); |
| 266 | } |
| 267 | |
| 268 | ret = fstdump_thread_inner(fstdump, sendrec, databuf, buffer_length); |
| 269 | |
| 270 | if (fstdump->real_thread) { |
| 271 | BDB_RELLOCK(); |
| 272 | bdb_thread_event(common->bdb_state, BDBTHR_EVENT_DONE_RDONLY); |
| 273 | } |
| 274 | } else { |
| 275 | Pthread_mutex_lock(&common->lock); |
| 276 | { |
| 277 | common->bdberr = BDBERR_MALLOC; |
| 278 | snprintf0(common->errmsg, sizeof(common->errmsg), "out of memory"); |
| 279 | } |
| 280 | Pthread_mutex_unlock(&common->lock); |
| 281 | } |
| 282 | |
| 283 | if (sendrec) |
| 284 | free(sendrec); |
| 285 | if (databuf) |
| 286 | free(databuf); |
| 287 | |
| 288 | return ret; |
no test coverage detected