Changeset 90eec9c0 in mainline for uspace/srv/bd/hr/raid4.c


Ignore:
Timestamp:
2024-11-10T21:34:49Z (6 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
1a60e645
Parents:
11111e4
Message:

hr: allocate xorbuf with whole request length

As it can be 64K at most at the moment, we can allocate
whole request size.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/hr/raid4.c

    r11111e4 r90eec9c0  
    8787
    8888/*
    89  * Return first bad extent
     89 * Returns (-1) if all extents are online,
     90 * else returns index of first bad one.
    9091 */
    9192static ssize_t hr_raid4_get_bad_ext(hr_volume_t *vol)
     
    150151{
    151152        errno_t rc;
    152         size_t i, j;
     153        size_t i;
    153154        void *xorbuf;
    154155        void *buf;
    155 
    156         xorbuf = malloc(vol->bsize);
     156        uint64_t len = vol->bsize * cnt;
     157
     158        xorbuf = malloc(len);
    157159        if (xorbuf == NULL)
    158160                return ENOMEM;
    159161
    160         buf = malloc(vol->bsize);
     162        buf = malloc(len);
    161163        if (buf == NULL) {
    162164                free(xorbuf);
     
    164166        }
    165167
    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);
    184183end:
    185184        free(xorbuf);
     
    192191{
    193192        errno_t rc;
    194         size_t i, j;
     193        size_t i;
    195194        void *xorbuf;
    196195        void *buf;
     196        uint64_t len = vol->bsize * cnt;
    197197
    198198        ssize_t bad = hr_raid4_get_bad_ext(vol);
     
    212212        }
    213213
    214         xorbuf = malloc(vol->bsize);
     214        xorbuf = malloc(len);
    215215        if (xorbuf == NULL)
    216216                return ENOMEM;
    217217
    218         buf = malloc(vol->bsize);
     218        buf = malloc(len);
    219219        if (buf == NULL) {
    220220                free(xorbuf);
     
    228228                 * write new parity
    229229                 */
    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);
    242240                        }
    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;
    251247        } else {
    252248                /*
     
    255251                 * write parity, new data
    256252                 */
    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;
    281273        }
    282274end:
     
    290282{
    291283        errno_t rc;
    292         size_t i, j;
     284        size_t i;
    293285        void *xorbuf;
    294286        void *buf;
    295 
    296         xorbuf = malloc(vol->bsize);
     287        uint64_t len = vol->bsize * cnt;
     288
     289        xorbuf = malloc(len);
    297290        if (xorbuf == NULL)
    298291                return ENOMEM;
    299292
    300         buf = malloc(vol->bsize);
     293        buf = malloc(len);
    301294        if (buf == NULL) {
    302295                free(xorbuf);
     
    304297        }
    305298
    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);
    326318end:
    327319        free(xorbuf);
Note: See TracChangeset for help on using the changeset viewer.