Changeset 90eec9c0 in mainline for uspace/srv/bd/hr/raid4.c
- Timestamp:
- 2024-11-10T21:34:49Z (6 months ago)
- Children:
- 1a60e645
- Parents:
- 11111e4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/hr/raid4.c
r11111e4 r90eec9c0 87 87 88 88 /* 89 * Return first bad extent 89 * Returns (-1) if all extents are online, 90 * else returns index of first bad one. 90 91 */ 91 92 static ssize_t hr_raid4_get_bad_ext(hr_volume_t *vol) … … 150 151 { 151 152 errno_t rc; 152 size_t i , j;153 size_t i; 153 154 void *xorbuf; 154 155 void *buf; 155 156 xorbuf = malloc(vol->bsize); 156 uint64_t len = vol->bsize * cnt; 157 158 xorbuf = malloc(len); 157 159 if (xorbuf == NULL) 158 160 return ENOMEM; 159 161 160 buf = malloc( vol->bsize);162 buf = malloc(len); 161 163 if (buf == NULL) { 162 164 free(xorbuf); … … 164 166 } 165 167 166 /* read all other extents in stripe */ 167 for (j = 0; j < cnt; j++) { 168 memset(xorbuf, 0, vol->bsize); 169 for (i = 0; i < vol->dev_no; i++) { 170 if (i == bad) { 171 continue; 172 } else { 173 rc = block_read_direct(vol->extents[i].svc_id, 174 block, 1, buf); 175 if (rc != EOK) 176 goto end; 177 xor(xorbuf, buf, vol->bsize); 178 } 179 } 180 memcpy(data, xorbuf, vol->bsize); 181 data = (void *) ((uintptr_t) data + vol->bsize); 182 block++; 183 } 168 /* read all other extents in the stripe */ 169 memset(xorbuf, 0, len); 170 for (i = 0; i < vol->dev_no; i++) { 171 if (i == bad) { 172 continue; 173 } else { 174 rc = block_read_direct(vol->extents[i].svc_id, block, 175 cnt, buf); 176 if (rc != EOK) 177 goto end; 178 xor(xorbuf, buf, len); 179 } 180 } 181 182 memcpy(data, xorbuf, len); 184 183 end: 185 184 free(xorbuf); … … 192 191 { 193 192 errno_t rc; 194 size_t i , j;193 size_t i; 195 194 void *xorbuf; 196 195 void *buf; 196 uint64_t len = vol->bsize * cnt; 197 197 198 198 ssize_t bad = hr_raid4_get_bad_ext(vol); … … 212 212 } 213 213 214 xorbuf = malloc( vol->bsize);214 xorbuf = malloc(len); 215 215 if (xorbuf == NULL) 216 216 return ENOMEM; 217 217 218 buf = malloc( vol->bsize);218 buf = malloc(len); 219 219 if (buf == NULL) { 220 220 free(xorbuf); … … 228 228 * write new parity 229 229 */ 230 for (j = 0; j < cnt; j++) { 231 memset(xorbuf, 0, vol->bsize); 232 for (i = 1; i < vol->dev_no; i++) { 233 if (i == (size_t) bad) { 234 continue; 235 } else { 236 rc = block_read_direct(vol->extents[i].svc_id, 237 ba, 1, buf); 238 if (rc != EOK) 239 goto end; 240 xor(xorbuf, buf, vol->bsize); 241 } 230 memset(xorbuf, 0, len); 231 for (i = 1; i < vol->dev_no; i++) { 232 if (i == (size_t) bad) { 233 continue; 234 } else { 235 rc = block_read_direct(vol->extents[i].svc_id, 236 ba, cnt, buf); 237 if (rc != EOK) 238 goto end; 239 xor(xorbuf, buf, len); 242 240 } 243 xor(xorbuf, data, vol->bsize); 244 rc = block_write_direct(vol->extents[0].svc_id, ba, 1, 245 xorbuf); 246 if (rc != EOK) 247 goto end; 248 data = (void *) ((uintptr_t) data + vol->bsize); 249 ba++; 250 } 241 } 242 xor(xorbuf, data, len); 243 rc = block_write_direct(vol->extents[0].svc_id, ba, cnt, 244 xorbuf); 245 if (rc != EOK) 246 goto end; 251 247 } else { 252 248 /* … … 255 251 * write parity, new data 256 252 */ 257 for (j = 0; j < cnt; j++) { 258 rc = block_read_direct(vol->extents[extent].svc_id, ba, 259 1, xorbuf); 260 if (rc != EOK) 261 goto end; 262 rc = block_read_direct(vol->extents[0].svc_id, ba, 1, 263 buf); 264 if (rc != EOK) 265 goto end; 266 xor(xorbuf, buf, vol->bsize); 267 268 xor(xorbuf, data, vol->bsize); 269 270 rc = block_write_direct(vol->extents[0].svc_id, ba, 1, 271 xorbuf); 272 if (rc != EOK) 273 goto end; 274 rc = block_write_direct(vol->extents[extent].svc_id, 275 ba, 1, data); 276 if (rc != EOK) 277 goto end; 278 data = (void *) ((uintptr_t) data + vol->bsize); 279 ba++; 280 } 253 rc = block_read_direct(vol->extents[extent].svc_id, ba, cnt, 254 xorbuf); 255 if (rc != EOK) 256 goto end; 257 rc = block_read_direct(vol->extents[0].svc_id, ba, cnt, buf); 258 if (rc != EOK) 259 goto end; 260 261 xor(xorbuf, buf, len); 262 263 xor(xorbuf, data, len); 264 265 rc = block_write_direct(vol->extents[0].svc_id, ba, cnt, 266 xorbuf); 267 if (rc != EOK) 268 goto end; 269 rc = block_write_direct(vol->extents[extent].svc_id, ba, cnt, 270 data); 271 if (rc != EOK) 272 goto end; 281 273 } 282 274 end: … … 290 282 { 291 283 errno_t rc; 292 size_t i , j;284 size_t i; 293 285 void *xorbuf; 294 286 void *buf; 295 296 xorbuf = malloc(vol->bsize); 287 uint64_t len = vol->bsize * cnt; 288 289 xorbuf = malloc(len); 297 290 if (xorbuf == NULL) 298 291 return ENOMEM; 299 292 300 buf = malloc( vol->bsize);293 buf = malloc(len); 301 294 if (buf == NULL) { 302 295 free(xorbuf); … … 304 297 } 305 298 306 for (j = 0; j < cnt; j++) { 307 memset(xorbuf, 0, vol->bsize); 308 for (i = 1; i < vol->dev_no; i++) { 309 if (i == extent) { 310 xor(xorbuf, data, vol->bsize); 311 } else { 312 rc = block_read_direct(vol->extents[i].svc_id, 313 block, 1, buf); 314 if (rc != EOK) 315 goto end; 316 xor(xorbuf, buf, vol->bsize); 317 } 318 } 319 rc = block_write_direct(vol->extents[0].svc_id, block, 1, 320 xorbuf); 321 if (rc != EOK) 322 goto end; 323 data = (void *) ((uintptr_t) data + vol->bsize); 324 block++; 325 } 299 /* 300 * parity = read and xor all other data extents, xor in new data 301 * 302 * XXX: subtract method 303 */ 304 memset(xorbuf, 0, len); 305 for (i = 1; i < vol->dev_no; i++) { 306 if (i == extent) { 307 xor(xorbuf, data, vol->bsize); 308 } else { 309 rc = block_read_direct(vol->extents[i].svc_id, block, 310 cnt, buf); 311 if (rc != EOK) 312 goto end; 313 xor(xorbuf, buf, len); 314 } 315 } 316 317 rc = block_write_direct(vol->extents[0].svc_id, block, cnt, xorbuf); 326 318 end: 327 319 free(xorbuf);
Note:
See TracChangeset
for help on using the changeset viewer.