Skip to content

Commit 71114ec

Browse files
ecashintorvalds
authored andcommitted
aoe: use dynamic number of remote ports for AoE storage target
Many AoE targets have four or fewer network ports, but some existing storage devices have many, and the AoE protocol sets no limit. This patch allows the use of more than eight remote MAC addresses per AoE target, while reducing the amount of memory used by the aoe driver in cases where there are many AoE targets with fewer than eight MAC addresses each. Signed-off-by: Ed Cashin <ecashin@coraid.com> Cc: Jens Axboe <axboe@kernel.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e52a293 commit 71114ec

4 files changed

Lines changed: 49 additions & 21 deletions

File tree

‎drivers/block/aoe/aoe.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ enum {
8484
enum {
8585
DEFAULTBCNT = 2 * 512, /* 2 sectors */
8686
MIN_BUFS = 16,
87-
NTARGETS = 8,
87+
NTARGETS = 4,
8888
NAOEIFS = 8,
8989
NSKBPOOLMAX = 256,
9090
NFACTIVE = 61,
@@ -185,9 +185,9 @@ struct aoedev {
185185
ulong maxbcnt;
186186
struct list_head factive[NFACTIVE]; /* hash of active frames */
187187
struct list_head rexmitq; /* deferred retransmissions */
188-
struct aoetgt *targets[NTARGETS];
188+
struct aoetgt **targets;
189+
ulong ntargets; /* number of allocated aoetgt pointers */
189190
struct aoetgt **tgt; /* target in use when working */
190-
ulong ntargets;
191191
ulong kicked;
192192
char ident[512];
193193
};

‎drivers/block/aoe/aoeblk.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static ssize_t aoedisk_show_netif(struct device *dev,
6767
nd = nds;
6868
ne = nd + ARRAY_SIZE(nds);
6969
t = d->targets;
70-
te = t + NTARGETS;
70+
te = t + d->ntargets;
7171
for (; t < te && *t; t++) {
7272
ifp = (*t)->ifs;
7373
e = ifp + NAOEIFS;

‎drivers/block/aoe/aoecmd.c‎

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ newframe(struct aoedev *d)
242242
int use_tainted;
243243
int has_untainted;
244244

245-
if (d->targets[0] == NULL) { /* shouldn't happen, but I'm paranoid */
245+
if (!d->targets || !d->targets[0]) {
246246
printk(KERN_ERR "aoe: NULL TARGETS!\n");
247247
return NULL;
248248
}
249249
tt = d->tgt; /* last used target */
250250
for (use_tainted = 0, has_untainted = 0;;) {
251251
tt++;
252-
if (tt >= &d->targets[NTARGETS] || !*tt)
252+
if (tt >= &d->targets[d->ntargets] || !*tt)
253253
tt = d->targets;
254254
t = *tt;
255255
if (!t->taint) {
@@ -1104,7 +1104,7 @@ gettgt(struct aoedev *d, char *addr)
11041104
struct aoetgt **t, **e;
11051105

11061106
t = d->targets;
1107-
e = t + NTARGETS;
1107+
e = t + d->ntargets;
11081108
for (; t < e && *t; t++)
11091109
if (memcmp((*t)->addr, addr, sizeof((*t)->addr)) == 0)
11101110
return *t;
@@ -1479,28 +1479,44 @@ aoecmd_ata_id(struct aoedev *d)
14791479
return skb;
14801480
}
14811481

1482+
static struct aoetgt **
1483+
grow_targets(struct aoedev *d)
1484+
{
1485+
ulong oldn, newn;
1486+
struct aoetgt **tt;
1487+
1488+
oldn = d->ntargets;
1489+
newn = oldn * 2;
1490+
tt = kcalloc(newn, sizeof(*d->targets), GFP_ATOMIC);
1491+
if (!tt)
1492+
return NULL;
1493+
memmove(tt, d->targets, sizeof(*d->targets) * oldn);
1494+
d->tgt = tt + (d->tgt - d->targets);
1495+
kfree(d->targets);
1496+
d->targets = tt;
1497+
d->ntargets = newn;
1498+
1499+
return &d->targets[oldn];
1500+
}
1501+
14821502
static struct aoetgt *
14831503
addtgt(struct aoedev *d, char *addr, ulong nframes)
14841504
{
14851505
struct aoetgt *t, **tt, **te;
14861506

14871507
tt = d->targets;
1488-
te = tt + NTARGETS;
1508+
te = tt + d->ntargets;
14891509
for (; tt < te && *tt; tt++)
14901510
;
14911511

14921512
if (tt == te) {
1493-
printk(KERN_INFO
1494-
"aoe: device addtgt failure; too many targets\n");
1495-
return NULL;
1513+
tt = grow_targets(d);
1514+
if (!tt)
1515+
goto nomem;
14961516
}
14971517
t = kzalloc(sizeof(*t), GFP_ATOMIC);
1498-
if (!t) {
1499-
printk(KERN_INFO "aoe: cannot allocate memory to add target\n");
1500-
return NULL;
1501-
}
1502-
1503-
d->ntargets++;
1518+
if (!t)
1519+
goto nomem;
15041520
t->nframes = nframes;
15051521
t->d = d;
15061522
memcpy(t->addr, addr, sizeof t->addr);
@@ -1509,6 +1525,10 @@ addtgt(struct aoedev *d, char *addr, ulong nframes)
15091525
t->maxout = t->nframes / 2;
15101526
INIT_LIST_HEAD(&t->ffree);
15111527
return *tt = t;
1528+
1529+
nomem:
1530+
pr_info("aoe: cannot allocate memory to add target\n");
1531+
return NULL;
15121532
}
15131533

15141534
static void
@@ -1518,7 +1538,7 @@ setdbcnt(struct aoedev *d)
15181538
int bcnt = 0;
15191539

15201540
t = d->targets;
1521-
e = t + NTARGETS;
1541+
e = t + d->ntargets;
15221542
for (; t < e && *t; t++)
15231543
if (bcnt == 0 || bcnt > (*t)->minbcnt)
15241544
bcnt = (*t)->minbcnt;
@@ -1662,7 +1682,7 @@ aoecmd_cleanslate(struct aoedev *d)
16621682
d->maxbcnt = 0;
16631683

16641684
t = d->targets;
1665-
te = t + NTARGETS;
1685+
te = t + d->ntargets;
16661686
for (; t < te && *t; t++)
16671687
aoecmd_wreset(*t);
16681688
}

‎drivers/block/aoe/aoedev.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ aoedev_downdev(struct aoedev *d)
214214

215215
/* reset window dressings */
216216
tt = d->targets;
217-
te = tt + NTARGETS;
217+
te = tt + d->ntargets;
218218
for (; tt < te && (t = *tt); tt++) {
219219
aoecmd_wreset(t);
220220
t->nout = 0;
@@ -284,7 +284,7 @@ freedev(struct aoedev *d)
284284
blk_cleanup_queue(d->blkq);
285285
}
286286
t = d->targets;
287-
e = t + NTARGETS;
287+
e = t + d->ntargets;
288288
for (; t < e && *t; t++)
289289
freetgt(d, *t);
290290
if (d->bufpool)
@@ -376,6 +376,8 @@ flush(const char __user *str, size_t cnt, int exiting)
376376
dd = &d->next;
377377
}
378378
spin_unlock(&d->lock);
379+
if (doomed)
380+
kfree(doomed->targets);
379381
kfree(doomed);
380382
}
381383
spin_unlock_irqrestore(&devlist_lock, flags);
@@ -456,6 +458,12 @@ aoedev_by_aoeaddr(ulong maj, int min, int do_alloc)
456458
d = kcalloc(1, sizeof *d, GFP_ATOMIC);
457459
if (!d)
458460
goto out;
461+
d->targets = kcalloc(NTARGETS, sizeof(*d->targets), GFP_ATOMIC);
462+
if (!d->targets) {
463+
kfree(d);
464+
goto out;
465+
}
466+
d->ntargets = NTARGETS;
459467
INIT_WORK(&d->work, aoecmd_sleepwork);
460468
spin_lock_init(&d->lock);
461469
skb_queue_head_init(&d->skbpool);

0 commit comments

Comments
 (0)