- Timestamp:
- 07/27/10 17:05:51 (12 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- 8608a0fa
- Parents:
- c69b593
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/ior-peek.c
r96bf151 rd08c691 104 104 /* Is the current buffer big enough? */ 105 105 if (DATA(io)->length < bytes_read) { 106 int res = 0; 107 106 108 if (DATA(io)->buffer) 107 109 free(DATA(io)->buffer); … … 109 111 DATA(io)->offset = 0; 110 112 #if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 111 /* We need to do this as read() of O_DIRECT might happen into this buffer. 112 * The docs suggest 512 bytes is all we need to align to, but I'm suspicious 113 * I expect disks with 4k blocks will arrive soon, and thus 4k is the minimum I'm 114 * willing to live with. 113 /* We need to do this as read() of O_DIRECT might happen into 114 * this buffer. The docs suggest 512 bytes is all we need to 115 * align to, but I'm suspicious. I expect disks with 4k blocks 116 * will arrive soon, and thus 4k is the minimum I'm willing to 117 * live with. 115 118 */ 116 posix_memalign(&DATA(io)->buffer, 4096, DATA(io)->length); 119 res = posix_memalign((void **)&DATA(io)->buffer, 4096, 120 DATA(io)->length); 121 if (res != 0) { 122 fprintf(stderr, "Error aligning IO buffer: %d\n", 123 res); 124 return res; 125 } 117 126 #else 118 127 DATA(io)->buffer = malloc(DATA(io)->length); … … 210 219 } 211 220 212 static void *alignedrealloc(void *old, size_t oldsize, size_t size )221 static void *alignedrealloc(void *old, size_t oldsize, size_t size, int *res) 213 222 { 214 223 #if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 … … 217 226 if (size < oldsize) 218 227 return old; 219 posix_memalign(&new, 4096, size); 228 *res = posix_memalign(&new, 4096, size); 229 if (*res != 0) { 230 fprintf(stderr, "Error aligning IO buffer: %d\n", *res); 231 232 return NULL; 233 } 220 234 assert(oldsize<size); 221 235 memcpy(new,old,oldsize); … … 231 245 { 232 246 off_t ret = 0; 247 int res = 0; 233 248 234 249 /* Is there enough data in the buffer to serve this request? */ … … 238 253 /* Round the read_amount up to the nearest MB */ 239 254 read_amount += PEEK_SIZE - ((DATA(io)->length + read_amount) % PEEK_SIZE); 240 DATA(io)->buffer = alignedrealloc(DATA(io)->buffer, DATA(io)->length, 241 DATA(io)->length + read_amount); 255 DATA(io)->buffer = alignedrealloc(DATA(io)->buffer, 256 DATA(io)->length, 257 DATA(io)->length + read_amount, &res); 258 259 if (DATA(io)->buffer == NULL) { 260 return res; 261 } 262 242 263 /* Use the child reader to read more data into our managed 243 264 * buffer */
Note: See TracChangeset
for help on using the changeset viewer.