Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144118319
D20483.id58125.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
8 KB
Referenced Files
None
Subscribers
None
D20483.id58125.diff
View Options
Index: stand/libsa/zfs/zfs.c
===================================================================
--- stand/libsa/zfs/zfs.c
+++ stand/libsa/zfs/zfs.c
@@ -418,7 +418,7 @@
/* Return of partial sector data requires a bounce buffer. */
if ((head > 0) || do_tail_read) {
- bouncebuf = zfs_alloc(secsz);
+ bouncebuf = malloc(secsz);
if (bouncebuf == NULL) {
printf("vdev_read: out of memory\n");
return (ENOMEM);
@@ -464,7 +464,7 @@
ret = 0;
error:
if (bouncebuf != NULL)
- zfs_free(bouncebuf, secsz);
+ free(bouncebuf);
return (ret);
}
Index: stand/libsa/zfs/zfsimpl.c
===================================================================
--- stand/libsa/zfs/zfsimpl.c
+++ stand/libsa/zfs/zfsimpl.c
@@ -76,9 +76,6 @@
static uint64_t dnode_cache_bn;
static char *dnode_cache_buf;
static char *zap_scratch;
-static char *zfs_temp_buf, *zfs_temp_end, *zfs_temp_ptr;
-
-#define TEMP_SIZE (1024 * 1024)
static int zio_read(const spa_t *spa, const blkptr_t *bp, void *buf);
static int zfs_get_root(const spa_t *spa, uint64_t *objid);
@@ -93,39 +90,12 @@
STAILQ_INIT(&zfs_vdevs);
STAILQ_INIT(&zfs_pools);
- zfs_temp_buf = malloc(TEMP_SIZE);
- zfs_temp_end = zfs_temp_buf + TEMP_SIZE;
- zfs_temp_ptr = zfs_temp_buf;
dnode_cache_buf = malloc(SPA_MAXBLOCKSIZE);
zap_scratch = malloc(SPA_MAXBLOCKSIZE);
zfs_init_crc();
}
-static void *
-zfs_alloc(size_t size)
-{
- char *ptr;
-
- if (zfs_temp_ptr + size > zfs_temp_end) {
- panic("ZFS: out of temporary buffer space");
- }
- ptr = zfs_temp_ptr;
- zfs_temp_ptr += size;
-
- return (ptr);
-}
-
-static void
-zfs_free(void *ptr, size_t size)
-{
-
- zfs_temp_ptr -= size;
- if (zfs_temp_ptr != ptr) {
- panic("ZFS: zfs_alloc()/zfs_free() mismatch");
- }
-}
-
static int
xdr_int(const unsigned char **xdr, int *ip)
{
@@ -957,7 +927,9 @@
if (psize < SPA_MINDEVSIZE)
return (EIO);
- tmp_label = zfs_alloc(sizeof(vdev_phys_t));
+ tmp_label = malloc(sizeof(vdev_phys_t));
+ if (tmp_label == NULL)
+ return (ENOMEM);
for (l = 0; l < VDEV_LABELS; l++) {
off = vdev_label_offset(psize, l,
@@ -988,7 +960,7 @@
}
}
- zfs_free(tmp_label, sizeof (vdev_phys_t));
+ free(tmp_label);
if (best_txg == 0)
return (EIO);
@@ -1119,7 +1091,9 @@
* the best uberblock and then we can actually access
* the contents of the pool.
*/
- upbuf = zfs_alloc(VDEV_UBERBLOCK_SIZE(vdev));
+ upbuf = malloc(VDEV_UBERBLOCK_SIZE(vdev));
+ if (upbuf == NULL)
+ return (ENOMEM);
up = (const struct uberblock *)upbuf;
for (l = 0; l < VDEV_LABELS; l++) {
for (i = 0; i < VDEV_UBERBLOCK_COUNT(vdev); i++) {
@@ -1148,7 +1122,7 @@
}
}
}
- zfs_free(upbuf, VDEV_UBERBLOCK_SIZE(vdev));
+ free(upbuf);
vdev->spa = spa;
if (spap != NULL)
@@ -1221,19 +1195,24 @@
size = BPE_GET_PSIZE(bp);
ASSERT(size <= BPE_PAYLOAD_SIZE);
- if (cpfunc != ZIO_COMPRESS_OFF)
- pbuf = zfs_alloc(size);
- else
+ if (cpfunc != ZIO_COMPRESS_OFF) {
+ pbuf = malloc(size);
+ if (pbuf == NULL) {
+ error = ENOMEM;
+ goto embedout;
+ }
+ } else {
pbuf = buf;
-
+ }
decode_embedded_bp_compressed(bp, pbuf);
error = 0;
if (cpfunc != ZIO_COMPRESS_OFF) {
error = zio_decompress_data(cpfunc, pbuf,
size, buf, BP_GET_LSIZE(bp));
- zfs_free(pbuf, size);
+ free(pbuf);
}
+embedout:
if (error != 0)
printf("ZFS: i/o error - unable to decompress block pointer data, error %d\n",
error);
@@ -1266,10 +1245,15 @@
if (P2PHASE(size, align) != 0)
size = P2ROUNDUP(size, align);
}
- if (size != BP_GET_PSIZE(bp) || cpfunc != ZIO_COMPRESS_OFF)
- pbuf = zfs_alloc(size);
- else
+ if (size != BP_GET_PSIZE(bp) || cpfunc != ZIO_COMPRESS_OFF) {
+ pbuf = malloc(size);
+ if (pbuf == NULL) {
+ printf("ZFS: i/o error - out of memory\n");
+ return (ENOMEM);
+ }
+ } else {
pbuf = buf;
+ }
if (DVA_GET_GANG(dva))
error = zio_read_gang(spa, bp, pbuf);
@@ -1283,7 +1267,7 @@
bcopy(pbuf, buf, BP_GET_PSIZE(bp));
}
if (buf != pbuf)
- zfs_free(pbuf, size);
+ free(pbuf);
if (error == 0)
break;
}
@@ -2279,10 +2263,11 @@
int error;
size = BP_GET_LSIZE(bp);
- buf = zfs_alloc(size);
+ buf = malloc(size);
+
error = zio_read(spa, bp, buf);
if (error != 0) {
- zfs_free(buf, size);
+ free(buf);
return (error);
}
sahdrp = buf;
@@ -2300,7 +2285,7 @@
sb->st_size = *(uint64_t *)((char *)sahdrp + hdrsize +
SA_SIZE_OFFSET);
if (buf != NULL)
- zfs_free(buf, size);
+ free(buf);
}
return (0);
@@ -2328,10 +2313,12 @@
bp = DN_SPILL_BLKPTR(dn);
size = BP_GET_LSIZE(bp);
- buf = zfs_alloc(size);
+ buf = malloc(size);
+ if (buf == NULL)
+ return (ENOMEM);
rc = zio_read(spa, bp, buf);
if (rc != 0) {
- zfs_free(buf, size);
+ free(buf);
return (rc);
}
sahdrp = buf;
@@ -2340,7 +2327,7 @@
p = (char *)((uintptr_t)sahdrp + hdrsize + SA_SYMLINK_OFFSET);
memcpy(path, p, psize);
if (buf != NULL)
- zfs_free(buf, size);
+ free(buf);
return (0);
}
/*
Index: sys/cddl/boot/zfs/zfssubr.c
===================================================================
--- sys/cddl/boot/zfs/zfssubr.c
+++ sys/cddl/boot/zfs/zfssubr.c
@@ -41,8 +41,8 @@
for (;;) ; \
} while (0)
-#define kmem_alloc(size, flag) zfs_alloc((size))
-#define kmem_free(ptr, size) zfs_free((ptr), (size))
+#define kmem_alloc(size, flag) malloc((size))
+#define kmem_free(ptr, size) free((ptr))
static void
zfs_init_crc(void)
@@ -374,9 +374,6 @@
return (crc);
}
-static void *zfs_alloc(size_t size);
-static void zfs_free(void *ptr, size_t size);
-
typedef struct raidz_col {
uint64_t rc_devidx; /* child device index for I/O */
uint64_t rc_offset; /* device offset */
@@ -979,7 +976,11 @@
log = 0; /* gcc */
psize = sizeof (invlog[0][0]) * n * nmissing;
- p = zfs_alloc(psize);
+ p = malloc(psize);
+ if (p == NULL) {
+ printf("vdev_raidz_matrix_reconstruct: Out of memory\n");
+ return;
+ }
for (pp = p, i = 0; i < nmissing; i++) {
invlog[i] = pp;
@@ -1035,7 +1036,7 @@
}
}
- zfs_free(p, psize);
+ free(p);
}
static int
@@ -1212,8 +1213,11 @@
ASSERT3U(acols, <=, scols);
- rm = zfs_alloc(offsetof(raidz_map_t, rm_col[scols]));
-
+ rm = malloc(offsetof(raidz_map_t, rm_col[scols]));
+ if (rm == NULL) {
+ printf("vdev_raidz_map_alloc: out of memory\n");
+ return (NULL);
+ }
rm->rm_cols = acols;
rm->rm_scols = scols;
rm->rm_bigcols = bc;
@@ -1257,9 +1261,17 @@
ASSERT3U(rm->rm_asize - asize, ==, rm->rm_nskip << unit_shift);
ASSERT3U(rm->rm_nskip, <=, nparity);
- for (c = 0; c < rm->rm_firstdatacol; c++)
- rm->rm_col[c].rc_data = zfs_alloc(rm->rm_col[c].rc_size);
-
+ for (c = 0; c < rm->rm_firstdatacol; c++) {
+ rm->rm_col[c].rc_data = malloc(rm->rm_col[c].rc_size);
+ /* Memory failure... unwind */
+ if (rm->rm_col[c].rc_data == NULL) {
+ while (c != 0) {
+ free(rm->rm_col[--c].rc_data);
+ }
+ free(rm);
+ return (NULL);
+ }
+ }
rm->rm_col[c].rc_data = data;
for (c = c + 1; c < acols; c++)
@@ -1310,9 +1322,9 @@
int c;
for (c = rm->rm_firstdatacol - 1; c >= 0; c--)
- zfs_free(rm->rm_col[c].rc_data, rm->rm_col[c].rc_size);
+ free(rm->rm_col[c].rc_data);
- zfs_free(rm, offsetof(raidz_map_t, rm_col[rm->rm_scols]));
+ free(rm);
}
static vdev_t *
@@ -1356,7 +1368,9 @@
rc = &rm->rm_col[c];
if (!rc->rc_tried || rc->rc_error != 0)
continue;
- orig[c] = zfs_alloc(rc->rc_size);
+ orig[c] = malloc(rc->rc_size);
+ if (orig[c] == NULL)
+ panic("raidz_parity_verify: ENOMEM");
bcopy(rc->rc_data, orig[c], rc->rc_size);
}
@@ -1370,7 +1384,7 @@
rc->rc_error = ECKSUM;
ret++;
}
- zfs_free(orig[c], rc->rc_size);
+ free(orig[c]);
}
return (ret);
@@ -1438,7 +1452,9 @@
ASSERT(orig[i] != NULL);
}
- orig[n - 1] = zfs_alloc(rm->rm_col[0].rc_size);
+ orig[n - 1] = malloc(rm->rm_col[0].rc_size);
+ if (orig[n - 1] == NULL)
+ panic("vdev_raidz_combrec: ENOMEM");
current = 0;
next = tgts[current];
@@ -1521,7 +1537,7 @@
n--;
done:
for (i = n - 1; i >= 0; i--) {
- zfs_free(orig[i], rm->rm_col[0].rc_size);
+ free(orig[i]);
}
return (ret);
@@ -1550,6 +1566,8 @@
rm = vdev_raidz_map_alloc(data, offset, bytes, tvd->v_ashift,
vd->v_nchildren, vd->v_nparity);
+ if (rm == NULL)
+ return (ENOMEM);
/*
* Iterate over the columns in reverse order so that we hit the parity
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 6, 1:54 AM (20 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28445552
Default Alt Text
D20483.id58125.diff (8 KB)
Attached To
Mode
D20483: stand: evict zfs_alloc/zfs_free
Attached
Detach File
Event Timeline
Log In to Comment