Skip to content

Commit cf33166

Browse files
authored
ZVOL: Minor code cleanup
- Remove zsda_tx field, it is used only once. - Remove unneeded string lengths checks, all names are terminated. - Replace few explicit MAXNAMELEN usages with sizeof(). - Change dsname from MAXNAMELEN to ZFS_MAX_DATASET_NAME_LEN, as expected by dsl_dataset_name(). Both are 256 bytes now, but it is better to be safe. This should have no functional difference. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Sponsored by: iXsystems, Inc. Closes #15535
1 parent 126efb5 commit cf33166

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

module/os/linux/zfs/zvol_os.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ zvol_alloc(dev_t dev, const char *name)
11991199
zso->zvo_queue->queuedata = zv;
12001200
zso->zvo_dev = dev;
12011201
zv->zv_open_count = 0;
1202-
strlcpy(zv->zv_name, name, MAXNAMELEN);
1202+
strlcpy(zv->zv_name, name, sizeof (zv->zv_name));
12031203

12041204
zfs_rangelock_init(&zv->zv_rangelock, NULL, NULL);
12051205
rw_init(&zv->zv_suspend_lock, NULL, RW_DEFAULT, NULL);

module/zfs/zvol.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,10 @@ typedef struct {
111111
uint64_t
112112
zvol_name_hash(const char *name)
113113
{
114-
int i;
115114
uint64_t crc = -1ULL;
116-
const uint8_t *p = (const uint8_t *)name;
117115
ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY);
118-
for (i = 0; i < MAXNAMELEN - 1 && *p; i++, p++) {
116+
for (const uint8_t *p = (const uint8_t *)name; *p != 0; p++)
119117
crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (*p)) & 0xFF];
120-
}
121118
return (crc);
122119
}
123120

@@ -138,8 +135,7 @@ zvol_find_by_name_hash(const char *name, uint64_t hash, int mode)
138135
hlist_for_each(p, ZVOL_HT_HEAD(hash)) {
139136
zv = hlist_entry(p, zvol_state_t, zv_hlink);
140137
mutex_enter(&zv->zv_state_lock);
141-
if (zv->zv_hash == hash &&
142-
strncmp(zv->zv_name, name, MAXNAMELEN) == 0) {
138+
if (zv->zv_hash == hash && strcmp(zv->zv_name, name) == 0) {
143139
/*
144140
* this is the right zvol, take the locks in the
145141
* right order
@@ -154,8 +150,7 @@ zvol_find_by_name_hash(const char *name, uint64_t hash, int mode)
154150
* to hold zvol_state_lock
155151
*/
156152
ASSERT(zv->zv_hash == hash &&
157-
strncmp(zv->zv_name, name, MAXNAMELEN)
158-
== 0);
153+
strcmp(zv->zv_name, name) == 0);
159154
}
160155
rw_exit(&zvol_state_lock);
161156
return (zv);
@@ -1526,9 +1521,9 @@ zvol_task_alloc(zvol_async_op_t op, const char *name1, const char *name2,
15261521
task->op = op;
15271522
task->value = value;
15281523

1529-
strlcpy(task->name1, name1, MAXNAMELEN);
1524+
strlcpy(task->name1, name1, sizeof (task->name1));
15301525
if (name2 != NULL)
1531-
strlcpy(task->name2, name2, MAXNAMELEN);
1526+
strlcpy(task->name2, name2, sizeof (task->name2));
15321527

15331528
return (task);
15341529
}
@@ -1573,7 +1568,6 @@ typedef struct zvol_set_prop_int_arg {
15731568
uint64_t zsda_value;
15741569
zprop_source_t zsda_source;
15751570
zfs_prop_t zsda_prop;
1576-
dmu_tx_t *zsda_tx;
15771571
} zvol_set_prop_int_arg_t;
15781572

15791573
/*
@@ -1601,7 +1595,7 @@ static int
16011595
zvol_set_common_sync_cb(dsl_pool_t *dp, dsl_dataset_t *ds, void *arg)
16021596
{
16031597
zvol_set_prop_int_arg_t *zsda = arg;
1604-
char dsname[MAXNAMELEN];
1598+
char dsname[ZFS_MAX_DATASET_NAME_LEN];
16051599
zvol_task_t *task;
16061600
uint64_t prop;
16071601

@@ -1650,13 +1644,12 @@ zvol_set_common_sync(void *arg, dmu_tx_t *tx)
16501644
int error;
16511645

16521646
VERIFY0(dsl_dir_hold(dp, zsda->zsda_name, FTAG, &dd, NULL));
1653-
zsda->zsda_tx = tx;
16541647

16551648
error = dsl_dataset_hold(dp, zsda->zsda_name, FTAG, &ds);
16561649
if (error == 0) {
16571650
dsl_prop_set_sync_impl(ds, zfs_prop_to_name(zsda->zsda_prop),
16581651
zsda->zsda_source, sizeof (zsda->zsda_value), 1,
1659-
&zsda->zsda_value, zsda->zsda_tx);
1652+
&zsda->zsda_value, tx);
16601653
dsl_dataset_rele(ds, FTAG);
16611654
}
16621655

0 commit comments

Comments
 (0)