Skip to content

Commit dc2f962

Browse files
committed
CP-34438: extend tap-ctl unpause to allow adding IO restriction
1 parent 19d2113 commit dc2f962

File tree

10 files changed

+142
-23
lines changed

10 files changed

+142
-23
lines changed

control/tap-ctl-ipc.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ tap_ctl_send_and_receive(int sfd, tapdisk_message_t *message,
161161

162162
int
163163
tap_ctl_send_and_receive_ex(int sfd, tapdisk_message_t *message,
164-
const char *logpath, uint8_t key_size,
164+
const char *logpath, const char *sockpath,
165+
uint8_t key_size,
165166
const uint8_t *encryption_key,
166167
struct timeval *timeout)
167168
{
@@ -203,6 +204,19 @@ tap_ctl_send_and_receive_ex(int sfd, tapdisk_message_t *message,
203204
}
204205
}
205206

207+
if (message->u.params.flags & TAPDISK_MESSAGE_FLAG_RATED) {
208+
DPRINTF("Sending socket for td-rated\n");
209+
char buf[TAPDISK_MESSAGE_MAX_PATH_LENGTH];
210+
snprintf(buf, TAPDISK_MESSAGE_MAX_PATH_LENGTH - 1, "%s", sockpath);
211+
212+
ret = write(sfd, &buf, sizeof(buf));
213+
214+
if (ret == -1) {
215+
EPRINTF("Failed to send sockpath with '%s' message\n",
216+
tapdisk_message_name(message->type));
217+
}
218+
}
219+
206220
err = tap_ctl_read_message(sfd, message, timeout);
207221
if (err) {
208222
EPRINTF("failed to receive '%s' message\n",
@@ -309,7 +323,9 @@ tap_ctl_connect_send_and_receive(int id, tapdisk_message_t *message,
309323

310324
int
311325
tap_ctl_connect_send_receive_ex(int id, tapdisk_message_t *message,
312-
const char *logpath, uint8_t key_size,
326+
const char *logpath,
327+
const char *sockpath,
328+
uint8_t key_size,
313329
const uint8_t *encryption_key,
314330
struct timeval *timeout)
315331
{
@@ -319,7 +335,7 @@ tap_ctl_connect_send_receive_ex(int id, tapdisk_message_t *message,
319335
if (err)
320336
return err;
321337

322-
err = tap_ctl_send_and_receive_ex(sfd, message, logpath, key_size, encryption_key, timeout);
338+
err = tap_ctl_send_and_receive_ex(sfd, message, logpath, sockpath, key_size, encryption_key, timeout);
323339

324340
close(sfd);
325341
return err;

control/tap-ctl-open.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ tap_ctl_open(const int id, const int minor, const char *params, int flags,
7575
}
7676
if (flags & (TAPDISK_MESSAGE_FLAG_ADD_LOG | TAPDISK_MESSAGE_FLAG_OPEN_ENCRYPTED)) {
7777
err = tap_ctl_connect_send_receive_ex(
78-
id, &message, logpath, key_size, encryption_key, NULL);
78+
id, &message, logpath, NULL, key_size, encryption_key, NULL);
7979
}
8080
else {
8181
err = tap_ctl_connect_send_and_receive(id, &message, NULL);

control/tap-ctl-unpause.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
int
4545
tap_ctl_unpause(const int id, const int minor, const char *params, int flags,
46-
char *secondary, const char *logpath)
46+
char *secondary, const char *logpath, const char *sockpath)
4747
{
4848
int err;
4949
tapdisk_message_t message;
@@ -65,8 +65,8 @@ tap_ctl_unpause(const int id, const int minor, const char *params, int flags,
6565
return -ENAMETOOLONG;
6666
}
6767
}
68-
if (logpath) {
69-
err = tap_ctl_connect_send_receive_ex(id, &message, logpath, 0, NULL, NULL);
68+
if (logpath || sockpath) {
69+
err = tap_ctl_connect_send_receive_ex(id, &message, logpath, sockpath, 0, NULL, NULL);
7070
}
7171
else {
7272
err = tap_ctl_connect_send_and_receive(id, &message, NULL);

control/tap-ctl.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,14 @@ tap_cli_unpause_usage(FILE *stream)
648648
{
649649
fprintf(stream, "usage: unpause <-p pid> <-m minor> [-a type:/path/to/file] "
650650
"[-2 secondary] "
651-
"[-c </path/to/logfile> insert log layer to track changed blocks]\n");
651+
"[-c </path/to/logfile> insert log layer to track changed blocks] "
652+
"[-l </path/to/td-rated/socket> use a td-rated valve for IO limiting]\n");
652653
}
653654

654655
int
655656
tap_cli_unpause(int argc, char **argv)
656657
{
657-
const char *args, *logpath;
658+
const char *args, *logpath, *sockpath;
658659
char *secondary;
659660
int c, pid, minor, flags;
660661

@@ -663,10 +664,11 @@ tap_cli_unpause(int argc, char **argv)
663664
args = NULL;
664665
secondary = NULL;
665666
flags = 0;
666-
logpath = NULL;
667+
logpath = NULL;
668+
sockpath = NULL;
667669

668670
optind = 0;
669-
while ((c = getopt(argc, argv, "p:m:a:2:c:h")) != -1) {
671+
while ((c = getopt(argc, argv, "p:m:a:2:c:l:h")) != -1) {
670672
switch (c) {
671673
case 'p':
672674
pid = atoi(optarg);
@@ -685,6 +687,10 @@ tap_cli_unpause(int argc, char **argv)
685687
logpath = optarg;
686688
flags |= TAPDISK_MESSAGE_FLAG_ADD_LOG;
687689
break;
690+
case 'l':
691+
sockpath = optarg;
692+
flags |= TAPDISK_MESSAGE_FLAG_RATED;
693+
break;
688694
case '?':
689695
goto usage;
690696
case 'h':
@@ -696,7 +702,7 @@ tap_cli_unpause(int argc, char **argv)
696702
if (pid == -1 || minor == -1)
697703
goto usage;
698704

699-
return tap_ctl_unpause(pid, minor, args, flags, secondary, logpath);
705+
return tap_ctl_unpause(pid, minor, args, flags, secondary, logpath, sockpath);
700706

701707
usage:
702708
tap_cli_unpause_usage(stderr);

drivers/tapdisk-control.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,25 @@ tapdisk_control_resume_vbd(struct tapdisk_ctl_conn *conn,
10701070
vbd->flags &= ~TD_OPEN_ADD_LOG;
10711071
}
10721072

1073+
if (request->u.params.flags & TAPDISK_MESSAGE_FLAG_RATED) {
1074+
char *sockpath = malloc(TAPDISK_MESSAGE_MAX_PATH_LENGTH + 1);
1075+
ret = read(conn->fd, sockpath, TAPDISK_MESSAGE_MAX_PATH_LENGTH);
1076+
if (ret < 0) {
1077+
err = -EIO;
1078+
free(sockpath);
1079+
goto out;
1080+
}
1081+
*(sockpath + TAPDISK_MESSAGE_MAX_PATH_LENGTH) = '\0';
1082+
vbd->rated_sockpath = sockpath;
1083+
vbd->flags |= TD_OPEN_RATED;
1084+
} else {
1085+
if (vbd->rated_sockpath) {
1086+
free (vbd->rated_sockpath);
1087+
vbd->rated_sockpath = NULL;
1088+
}
1089+
vbd->flags &= ~TD_OPEN_RATED;
1090+
}
1091+
10731092
if (request->u.params.path[0])
10741093
desc = request->u.params.path;
10751094

drivers/tapdisk-vbd.c

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,55 @@ static int tapdisk_vbd_add_dirty_log(td_vbd_t *vbd)
570570
return err;
571571
}
572572

573+
static int tapdisk_vbd_add_rated(td_vbd_t *vbd)
574+
{
575+
int err;
576+
td_driver_t *driver;
577+
td_image_t *valve, *parent;
578+
579+
driver = NULL;
580+
valve = NULL;
581+
582+
DPRINTF("VALVE:tapdisk_vbd_add_rated called for %s with %s\n",
583+
vbd->name, vbd->rated_sockpath);
584+
585+
parent = tapdisk_vbd_first_image(vbd);
586+
587+
if (!parent)
588+
return -EINVAL;
589+
590+
valve = tapdisk_image_allocate(vbd->rated_sockpath,
591+
DISK_TYPE_VALVE,
592+
parent->flags);
593+
594+
if (!valve)
595+
return -ENOMEM;
596+
597+
driver = tapdisk_driver_allocate(valve->type,
598+
valve->name,
599+
valve->flags);
600+
601+
if (!driver) {
602+
err = -ENOMEM;
603+
goto fail;
604+
}
605+
606+
driver->info = parent->driver->info;
607+
valve->driver = driver;
608+
609+
err = td_open(valve, &vbd->encryption);
610+
if (err)
611+
goto fail;
612+
613+
list_add(&valve->next, parent->next.prev);
614+
tapdisk_vbd_debug(vbd);
615+
return 0;
616+
617+
fail:
618+
tapdisk_image_free(valve);
619+
return err;
620+
}
621+
573622
int
574623
tapdisk_vbd_open_vdi(td_vbd_t *vbd, const char *name, td_flag_t flags, int prt_devnum)
575624
{
@@ -623,9 +672,25 @@ tapdisk_vbd_open_vdi(td_vbd_t *vbd, const char *name, td_flag_t flags, int prt_d
623672
goto fail;
624673
}
625674

675+
if (td_flag_test(vbd->flags, TD_OPEN_RATED)) {
676+
if (!vbd->rated_sockpath) {
677+
err = -EINVAL;
678+
goto fail;
679+
}
680+
err = tapdisk_vbd_add_rated(vbd);
681+
if (err) {
682+
EPRINTF("VBD %d Error adding valve, %s\n",
683+
vbd->uuid, strerror(-err));
684+
goto fail;
685+
}
686+
}
687+
626688
err = tapdisk_vbd_validate_chain(vbd);
627-
if (err)
689+
if (err) {
690+
EPRINTF("VBD: failed to validate chain %s\n",
691+
strerror(-err));
628692
goto fail;
693+
}
629694

630695
if (td_flag_test(vbd->flags, TD_OPEN_SECONDARY)) {
631696
err = tapdisk_vbd_add_secondary(vbd);
@@ -637,13 +702,13 @@ tapdisk_vbd_open_vdi(td_vbd_t *vbd, const char *name, td_flag_t flags, int prt_d
637702
}
638703
}
639704

640-
err = vbd_stats_create(vbd);
641-
if (err)
642-
goto fail;
705+
err = vbd_stats_create(vbd);
706+
if (err)
707+
goto fail;
643708

644-
err = td_metrics_vdi_start(vbd->tap->minor, &vbd->vdi_stats);
645-
if (err)
646-
goto fail;
709+
err = td_metrics_vdi_start(vbd->tap->minor, &vbd->vdi_stats);
710+
if (err)
711+
goto fail;
647712
if (tmp != vbd->name)
648713
free(tmp);
649714

@@ -764,6 +829,10 @@ tapdisk_vbd_shutdown(td_vbd_t *vbd)
764829
tapdisk_vbd_detach(vbd);
765830
tapdisk_server_remove_vbd(vbd);
766831
free(vbd->name);
832+
if (vbd->logpath)
833+
free(vbd->logpath);
834+
if (vbd->rated_sockpath)
835+
free(vbd->rated_sockpath);
767836
free(vbd);
768837

769838
return 0;

drivers/tapdisk-vbd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ struct td_vbd_handle {
166166
struct td_vbd_encryption encryption;
167167

168168
bool watchdog_warned;
169+
170+
/* Socket path for IO rating service */
171+
char *rated_sockpath;
169172
};
170173

171174
#define tapdisk_vbd_for_each_request(vreq, tmp, list) \

drivers/tapdisk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ extern unsigned int PAGE_SHIFT;
102102
#define TD_OPEN_STANDBY 0x00800
103103
#define TD_IGNORE_ENOSPC 0x01000
104104
#define TD_OPEN_NO_O_DIRECT 0x02000
105+
#define TD_OPEN_RATED 0x04000
105106

106107
#define TD_CREATE_SPARSE 0x00001
107108
#define TD_CREATE_MULTITYPE 0x00002

include/tap-ctl.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ int tap_ctl_connect_send_and_receive(int id,
8080
int tap_ctl_connect_send_receive_ex(int id,
8181
tapdisk_message_t *message,
8282
const char *logpath,
83+
const char *sockpath,
8384
uint8_t key_size,
8485
const uint8_t *encryption_key,
8586
struct timeval *timeout);
@@ -135,14 +136,17 @@ int tap_ctl_pause(const int id, const int minor, struct timeval *timeout);
135136
/**
136137
* Unpauses the VBD
137138
*
138-
* @param pid the process ID of the tapdisk
139+
* @param id the process ID of the tapdisk
140+
* @param minor the minor device number for the tapdisk
139141
* @param flags TODO
140142
* @param secondary TODO
141-
* @param uuid
142-
* @param new_params the new VDI to use (type:/path/to/file), optional
143+
* @param params the new VDI to use (type:/path/to/file), optional
144+
* @param logpath path for changed block tracking log
145+
* @param sockpath path for socket to connect td-rated valve layer
143146
*/
144147
int tap_ctl_unpause(const int id, const int minor, const char *params,
145-
int flags, char *secondary, const char *logpath);
148+
int flags, char *secondary, const char *logpath,
149+
const char *sockpath);
146150

147151
ssize_t tap_ctl_stats(pid_t pid, int minor, char *buf, size_t size);
148152
int tap_ctl_stats_fwrite(pid_t pid, int minor, FILE *out);

include/tapdisk-message.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#define TAPDISK_MESSAGE_FLAG_STANDBY 0x100
5757
#define TAPDISK_MESSAGE_FLAG_NO_O_DIRECT 0x200
5858
#define TAPDISK_MESSAGE_FLAG_OPEN_ENCRYPTED 0x400
59+
#define TAPDISK_MESSAGE_FLAG_RATED 0x800
5960

6061
typedef struct tapdisk_message tapdisk_message_t;
6162
typedef uint32_t tapdisk_message_flag_t;

0 commit comments

Comments
 (0)