Skip to content

Commit c300690

Browse files
utkarshmani1997vishnuitta
authored andcommitted
fix(cherry-pick): commits to v0.7.x from replication (#172)
* [TA3891] cherry-pick: Add missing metrics (#85) * cherry-pick: Fixed typo in istgt/src/istgt_lu_ctl.c (#161) * [TA3890] cherry-pick: push prod build Signed-off-by: Utkarsh Mani Tripathi <[email protected]>
1 parent 28d62a7 commit c300690

File tree

9 files changed

+174
-21
lines changed

9 files changed

+174
-21
lines changed

build_image.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#!/bin/bash
22
set -e
33

4+
pwd
5+
make clean
6+
sh autogen.sh
7+
./configure --enable-replication
8+
make clean
9+
make
10+
411
BUILD_DATE=$(date +'%Y%m%d%H%M%S')
512
REPO_NAME="openebs/cstor-istgt"
613

src/istgt_iscsi.c

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,7 +3467,9 @@ istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
34673467
lu_cmd.sense_alloc_len = 0; //conn->snsbufsize;
34683468
lu_cmd.sense_data_len = 0;
34693469
lu_cmd.connGone = 0;
3470-
3470+
#ifdef REPLICATION
3471+
clock_gettime(CLOCK_MONOTONIC_RAW, &lu_cmd.start_rw_time);
3472+
#endif
34713473
ISTGT_TRACELOG(ISTGT_TRACE_ISCSI,
34723474
"LU%d: CSN:%x ITT:%x (%lu/%u)[0x%x %lx+%x] PG=0x%4.4x, LUN=0x%lx "
34733475
"ExpStatSN=%x StatSN=%x ExpCmdSN=%x MaxCmdSN=%x "
@@ -5462,7 +5464,7 @@ prof_log(ISTGT_LU_CMD_Ptr p, const char *caller)
54625464
struct timespec *_s = &(p->times[baseindx]);
54635465
struct timespec *_n = &(p->times[_inx]);
54645466
struct timespec _r;
5465-
ISTGT_LU_DISK *spec;
5467+
ISTGT_LU_DISK *spec;
54665468
unsigned long secs, nsecs;
54675469

54685470
if ((_n->tv_nsec - _s->tv_nsec) < 0) {
@@ -5480,7 +5482,7 @@ prof_log(ISTGT_LU_CMD_Ptr p, const char *caller)
54805482
len = (p->lblen * spec->blocklen)/ 1024;
54815483
for(; (x < len && ind < 9); x *= 2, ind++);
54825484
}
5483-
else
5485+
else
54845486
ind = 0;
54855487
switch(p->cdb0) {
54865488
case SBC_WRITE_6:
@@ -5529,7 +5531,7 @@ prof_log(ISTGT_LU_CMD_Ptr p, const char *caller)
55295531
spec->IO_size[ind].cmp_n_write.tdiff[i].tv_sec = p->tdiff[i].tv_sec;
55305532
spec->IO_size[ind].cmp_n_write.tdiff[i].tv_nsec = p->tdiff[i].tv_nsec;
55315533
}
5532-
}
5534+
}
55335535
break;
55345536
case SBC_UNMAP:
55355537
if((spec->IO_size[ind].unmp.total_time.tv_sec < _r.tv_sec) || (spec->IO_size[ind].unmp.total_time.tv_sec == _r.tv_sec && spec->IO_size[ind].unmp.total_time.tv_nsec < _r.tv_nsec)) {
@@ -5647,6 +5649,51 @@ prof_log(ISTGT_LU_CMD_Ptr p, const char *caller)
56475649
}
56485650
}
56495651

5652+
#ifdef REPLICATION
5653+
static void
5654+
update_cummulative_rw_time(ISTGT_LU_TASK_Ptr lu_task)
5655+
{
5656+
ISTGT_LU_DISK *spec = NULL;
5657+
struct timespec endtime, diff;
5658+
uint64_t ns = 0;
5659+
5660+
switch(lu_task->lu_cmd.cdb0) {
5661+
case SBC_WRITE_6:
5662+
case SBC_WRITE_10:
5663+
case SBC_WRITE_12:
5664+
case SBC_WRITE_16:
5665+
case SBC_WRITE_AND_VERIFY_10:
5666+
case SBC_WRITE_AND_VERIFY_12:
5667+
case SBC_WRITE_AND_VERIFY_16:
5668+
spec = (ISTGT_LU_DISK *)
5669+
lu_task->lu_cmd.lu->lun[0].spec;
5670+
clock_gettime(CLOCK_MONOTONIC_RAW, &endtime);
5671+
timesdiff(CLOCK_MONOTONIC_RAW,
5672+
lu_task->lu_cmd.start_rw_time,
5673+
endtime, diff);
5674+
ns = diff.tv_sec*1000000000;
5675+
ns += diff.tv_nsec;
5676+
__sync_fetch_and_add(&spec->totalwritetime, ns);
5677+
break;
5678+
case SBC_READ_6:
5679+
case SBC_READ_10:
5680+
case SBC_READ_12:
5681+
case SBC_READ_16:
5682+
spec = (ISTGT_LU_DISK *)
5683+
lu_task->lu_cmd.lu->lun[0].spec;
5684+
clock_gettime(CLOCK_MONOTONIC_RAW, &endtime);
5685+
timesdiff(CLOCK_MONOTONIC_RAW,
5686+
lu_task->lu_cmd.start_rw_time,
5687+
endtime, diff);
5688+
ns = diff.tv_sec*1000000000;
5689+
ns += diff.tv_nsec;
5690+
__sync_fetch_and_add(&spec->totalreadtime, ns);
5691+
break;
5692+
}
5693+
return;
5694+
}
5695+
#endif
5696+
56505697
static void *
56515698
sender(void *arg)
56525699
{
@@ -5723,6 +5770,10 @@ sender(void *arg)
57235770
lu_task->lock = 1;
57245771
timediff(&lu_task->lu_cmd, 'r', __LINE__);
57255772
if (lu_task->type == ISTGT_LU_TASK_RESPONSE) {
5773+
#ifdef REPLICATION
5774+
update_cummulative_rw_time(lu_task);
5775+
#endif
5776+
57265777
/* send DATA-IN, SCSI status */
57275778
rc = istgt_iscsi_task_response(conn, lu_task);
57285779
if (rc < 0) {

src/istgt_iscsi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "istgt_lu.h"
3636
#include "istgt_queue.h"
3737
#include <sys/uio.h>
38+
/* Basic header segment length */
3839
#define ISCSI_BHS_LEN 48
3940
#define ISCSI_ALIGNMENT 4
4041
/* support version - RFC3720(10.12.4) */

src/istgt_lu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3724,6 +3724,9 @@ istgt_lu_create_task(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd, int lun, ISTGT_LU_D
37243724

37253725
}
37263726

3727+
#ifdef REPLICATION
3728+
lu_task->lu_cmd.start_rw_time = lu_cmd->start_rw_time;
3729+
#endif
37273730
lu_task->condwait = 0;
37283731
lu_task->offset = 0;
37293732
lu_task->req_execute = 0;

src/istgt_lu.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ typedef struct istgt_lu_cmd_t {
429429
uint8_t release_aborted;
430430
#ifdef REPLICATION
431431
uint32_t luworkerindx;
432+
struct timespec start_rw_time;
432433
#endif
433434
} ISTGT_LU_CMD;
434435
typedef ISTGT_LU_CMD *ISTGT_LU_CMD_Ptr;
@@ -781,6 +782,10 @@ typedef struct istgt_lu_disk_t {
781782
uint64_t reads;
782783
uint64_t readbytes;
783784
uint64_t writebytes;
785+
uint64_t totalreadtime;
786+
uint64_t totalwritetime;
787+
uint64_t totalreadblockcount;
788+
uint64_t totalwriteblockcount;
784789
#endif
785790
/* modify lun */
786791
int dofake;

src/istgt_lu_ctl.c

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,10 +2980,17 @@ istgt_uctl_cmd_iostats(UCTL_Ptr uctl)
29802980
ISTGT_LU_Ptr lu;
29812981
int rc, length;
29822982
uint64_t usedlogicalblocks;
2983+
struct timespec now;
2984+
uint64_t time_diff;
29832985
/* instantiate json_object from json-c library. */
29842986
struct json_object *jobj;
2985-
/* these are utility variables that will be freed at the end of the function. */
2986-
char *writes, *reads, *totalreadbytes, *totalwritebytes, *size, *usedblocks, *sectorsize;
2987+
/*
2988+
* these are utility variables that will be freed
2989+
* at the end of the function.
2990+
*/
2991+
char *writes, *reads, *totalreadbytes, *totalwritebytes, *size,
2992+
*usedblocks, *sectorsize, *uptime, *totalreadtime, *totalwritetime,
2993+
*totalreadblockcount, *totalwriteblockcount;
29872994
ISTGT_LU_DISK *spec;
29882995
MTX_LOCK(&specq_mtx);
29892996
TAILQ_FOREACH(spec, &spec_q, spec_next) {
@@ -3011,33 +3018,89 @@ istgt_uctl_cmd_iostats(UCTL_Ptr uctl)
30113018
length = snprintf(NULL, 0, "%"PRIu64, spec->size);
30123019
size = malloc(length + 1);
30133020
snprintf(size, length + 1, "%"PRIu64, spec->size);
3014-
usedlogicalblocks = ( spec->stats.used / spec->blocklen ) ;
3021+
3022+
usedlogicalblocks = (spec->stats.used / spec->blocklen);
30153023

30163024
length = snprintf(NULL, 0, "%"PRIu64, usedlogicalblocks);
30173025
usedblocks = malloc(length + 1);
3018-
snprintf(usedblocks, length + 1, "%"PRIu64, usedlogicalblocks);
3026+
snprintf(usedblocks, length + 1, "%"PRIu64,
3027+
usedlogicalblocks);
30193028

30203029
length = snprintf(NULL, 0, "%"PRIu64, spec->blocklen);
30213030
sectorsize = malloc(length + 1);
30223031
snprintf(sectorsize, length + 1, "%"PRIu64, spec->blocklen);
30233032

3033+
length = snprintf(NULL, 0, "%"PRIu64, spec->totalreadtime);
3034+
totalreadtime = malloc(length + 1);
3035+
snprintf(totalreadtime, length + 1, "%"PRIu64,
3036+
spec->totalreadtime);
3037+
3038+
length = snprintf(NULL, 0, "%"PRIu64, spec->totalwritetime);
3039+
totalwritetime = malloc(length + 1);
3040+
snprintf(totalwritetime, length + 1, "%"PRIu64,
3041+
spec->totalwritetime);
3042+
3043+
length = snprintf(NULL, 0, "%"PRIu64,
3044+
spec->totalwriteblockcount);
3045+
totalwriteblockcount = malloc(length + 1);
3046+
snprintf(totalwriteblockcount, length + 1, "%"PRIu64,
3047+
spec->totalwriteblockcount);
3048+
3049+
length = snprintf(NULL, 0, "%"PRIu64,
3050+
spec->totalreadblockcount);
3051+
totalreadblockcount = malloc(length + 1);
3052+
snprintf(totalreadblockcount, length + 1, "%"PRIu64,
3053+
spec->totalreadblockcount);
3054+
3055+
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
3056+
time_diff = (uint64_t)(now.tv_sec - istgt_start_time.tv_sec);
3057+
length = snprintf(NULL, 0, "%"PRIu64, time_diff);
3058+
uptime = malloc(length + 1);
3059+
snprintf(uptime, length + 1, "%"PRIu64, time_diff);
3060+
30243061
json_object *jreads = json_object_new_string(reads); /* instantiate child object */
30253062
json_object *jwrites = json_object_new_string(writes);
3026-
json_object *jtotalreadbytes = json_object_new_string(totalreadbytes);
3027-
json_object *jtotalwritebytes = json_object_new_string(totalwritebytes);
3063+
json_object *jtotalreadbytes =
3064+
json_object_new_string(totalreadbytes);
3065+
json_object *jtotalwritebytes =
3066+
json_object_new_string(totalwritebytes);
30283067
json_object *jsize = json_object_new_string(size);
3029-
json_object *jusedlogicalblocks = json_object_new_string(usedblocks);
3068+
json_object *jusedlogicalblocks =
3069+
json_object_new_string(usedblocks);
30303070
json_object *jsectorsize = json_object_new_string(sectorsize);
3031-
3032-
json_object_object_add(jobj, "WriteIOPS", jwrites); /* add values to object field */
3071+
json_object *juptime = json_object_new_string(uptime);
3072+
json_object *jtotalreadtime = json_object_new_string(
3073+
totalreadtime);
3074+
json_object *jtotalwritetime = json_object_new_string(
3075+
totalwritetime);
3076+
json_object *jtotalreadblockcount = json_object_new_string(
3077+
totalreadblockcount);
3078+
json_object *jtotalwriteblockcount = json_object_new_string(
3079+
totalwriteblockcount);
3080+
3081+
json_object_object_add(jobj, "WriteIOPS",
3082+
jwrites); /* add values to object field */
30333083
json_object_object_add(jobj, "ReadIOPS", jreads);
3034-
json_object_object_add(jobj, "TotalWriteBytes", jtotalwritebytes);
3035-
json_object_object_add(jobj, "TotalReadBytes", jtotalreadbytes);
3084+
json_object_object_add(jobj, "TotalWriteBytes",
3085+
jtotalwritebytes);
3086+
json_object_object_add(jobj, "TotalReadBytes",
3087+
jtotalreadbytes);
30363088
json_object_object_add(jobj, "Size", jsize);
3037-
json_object_object_add(jobj, "UsedLogicalBlocks", jusedlogicalblocks);
3089+
json_object_object_add(jobj, "UsedLogicalBlocks",
3090+
jusedlogicalblocks);
30383091
json_object_object_add(jobj, "SectorSize", jsectorsize);
3039-
3040-
istgt_uctl_snprintf(uctl, "%s %s\n", uctl->cmd, json_object_to_json_string(jobj));
3092+
json_object_object_add(jobj, "Uptime", juptime);
3093+
json_object_object_add(jobj, "TotalReadTime",
3094+
jtotalreadtime);
3095+
json_object_object_add(jobj, "TotalWriteTime",
3096+
jtotalwritetime);
3097+
json_object_object_add(jobj, "TotalReadBlockCount",
3098+
jtotalreadblockcount);
3099+
json_object_object_add(jobj, "TotalWriteBlockCount",
3100+
jtotalwriteblockcount);
3101+
3102+
istgt_uctl_snprintf(uctl, "%s %s\n",
3103+
uctl->cmd, json_object_to_json_string(jobj));
30413104
rc = istgt_uctl_writeline(uctl);
30423105
if (rc != UCTL_CMD_OK){
30433106
// free the pointers
@@ -3048,6 +3111,11 @@ istgt_uctl_cmd_iostats(UCTL_Ptr uctl)
30483111
free(size);
30493112
free(usedblocks);
30503113
free(sectorsize);
3114+
free(uptime);
3115+
free(totalreadtime);
3116+
free(totalwritetime);
3117+
free(totalreadblockcount);
3118+
free(totalwriteblockcount);
30513119
/* freeing root json_object will free all the allocated memory
30523120
** associated with the json_object.
30533121
*/
@@ -3062,6 +3130,11 @@ istgt_uctl_cmd_iostats(UCTL_Ptr uctl)
30623130
free(size);
30633131
free(usedblocks);
30643132
free(sectorsize);
3133+
free(uptime);
3134+
free(totalreadtime);
3135+
free(totalwritetime);
3136+
free(totalreadblockcount);
3137+
free(totalwriteblockcount);
30653138
json_object_put(jobj);
30663139
}
30673140
MTX_UNLOCK(&specq_mtx);

src/istgt_lu_disk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5640,6 +5640,7 @@ istgt_lu_disk_lbread(ISTGT_LU_DISK *spec, CONN_Ptr conn __attribute__((__unused_
56405640
rc = pread(spec->fd, data, nbytes, offset);
56415641
#endif
56425642
timediffw(lu_cmd, 'D');
5643+
56435644
exitblockingcall(endofmacro2)
56445645
if (markedForFree == 1 || markedForReturn == 1) {
56455646
ISTGT_TRACELOG(ISTGT_TRACE_NET, "c#%d connGone(%d)OrMarkedReturn(%d):%p:%d pendingIO:%d (read:%zd/%zd lba:%lu+%u)",

src/replication.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ cstor_conn_ops_t cstor_ops = {
3232

3333
int replication_initialized = 0;
3434
size_t rcmd_mempool_count = RCMD_MEMPOOL_ENTRIES;
35+
struct timespec istgt_start_time;
3536

3637
static int start_rebuild(void *buf, replica_t *replica, uint64_t data_len);
3738
static void handle_mgmt_conn_error(replica_t *r, int sfd, struct epoll_event *events,
@@ -44,6 +45,7 @@ static int handle_mgmt_event_fd(replica_t *replica);
4445

4546
#define build_rcomm_cmd(rcomm_cmd, cmd, offset, nbytes) \
4647
do { \
48+
uint64_t blockcnt = 0; \
4749
rcomm_cmd = malloc(sizeof (*rcomm_cmd)); \
4850
memset(rcomm_cmd, 0, sizeof (*rcomm_cmd)); \
4951
rcomm_cmd->copies_sent = 0; \
@@ -72,7 +74,11 @@ static int handle_mgmt_event_fd(replica_t *replica);
7274
rcomm_cmd->opcode = ZVOL_OPCODE_WRITE; \
7375
rcomm_cmd->iovcnt = cmd->iobufindx + 1; \
7476
__sync_add_and_fetch(&spec->writes, 1); \
75-
__sync_add_and_fetch(&spec->writebytes, nbytes);\
77+
__sync_add_and_fetch(&spec->writebytes, \
78+
nbytes); \
79+
blockcnt = (nbytes/spec->blocklen); \
80+
__sync_add_and_fetch(&spec->totalwriteblockcount,\
81+
blockcnt); \
7682
break; \
7783
\
7884
case SBC_READ_6: \
@@ -82,7 +88,11 @@ static int handle_mgmt_event_fd(replica_t *replica);
8288
rcomm_cmd->opcode = ZVOL_OPCODE_READ; \
8389
rcomm_cmd->iovcnt = 0; \
8490
__sync_add_and_fetch(&spec->reads, 1); \
85-
__sync_add_and_fetch(&spec->readbytes, nbytes);\
91+
__sync_add_and_fetch(&spec->readbytes, \
92+
nbytes); \
93+
blockcnt = (nbytes/spec->blocklen); \
94+
__sync_add_and_fetch(&spec->totalreadblockcount,\
95+
blockcnt); \
8696
break; \
8797
\
8898
case SBC_SYNCHRONIZE_CACHE_10: \
@@ -2448,7 +2458,6 @@ replicate(ISTGT_LU_DISK *spec, ISTGT_LU_CMD_Ptr cmd, uint64_t offset, uint64_t n
24482458

24492459
ASSERT(spec->io_seq);
24502460
build_rcomm_cmd(rcomm_cmd, cmd, offset, nbytes);
2451-
24522461
retry_read:
24532462
replica_choosen = false;
24542463
skip_count = 0;
@@ -2916,6 +2925,7 @@ initialize_replication()
29162925
REPLICA_ERRLOG("Failed to init specq_mtx err(%d)\n", rc);
29172926
return -1;
29182927
}
2928+
clock_gettime(CLOCK_MONOTONIC_RAW, &istgt_start_time);
29192929
return 0;
29202930
}
29212931

src/replication.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ typedef struct known_replica_s {
164164
uint64_t zvol_guid;
165165
} known_replica_t;
166166

167+
extern struct timespec istgt_start_time;
168+
167169
void *init_replication(void *);
168170
int make_socket_non_blocking(int);
169171
int send_mgmtack(int, zvol_op_code_t, void *, char *, int);

0 commit comments

Comments
 (0)