Skip to content

Commit 386b12d

Browse files
bmarzinsmwilck
authored andcommitted
libmpathpersist: use check_holding_reservation in mpath_prout_rel
Instead of open-coding mostly the same work, just make mpath_prout_rel() call check_holding_reservation(). Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Reviewed-by: Martin Wilck <mwilck@suse.com>
1 parent 60b1da9 commit 386b12d

1 file changed

Lines changed: 35 additions & 51 deletions

File tree

libmpathpersist/mpath_persist_int.c

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -639,22 +639,51 @@ static int preempt_all(struct multipath *mpp, int rq_servact, int rq_scope,
639639
noisy, false);
640640
}
641641

642+
static int
643+
reservation_key_matches(struct multipath *mpp, uint8_t *key, unsigned int *type)
644+
{
645+
struct prin_resp resp = {{{.prgeneration = 0}}};
646+
int status;
647+
648+
status = mpath_prin_activepath(mpp, MPATH_PRIN_RRES_SA, &resp, 0);
649+
if (status != MPATH_PR_SUCCESS) {
650+
condlog(0, "%s: pr in read reservation command failed.", mpp->wwid);
651+
return YNU_UNDEF;
652+
}
653+
if (!resp.prin_descriptor.prin_readresv.additional_length)
654+
return YNU_NO;
655+
if (memcmp(key, resp.prin_descriptor.prin_readresv.key, 8) == 0) {
656+
if (type)
657+
*type = resp.prin_descriptor.prin_readresv.scope_type &
658+
MPATH_PR_TYPE_MASK;
659+
return YNU_YES;
660+
}
661+
return YNU_NO;
662+
}
663+
664+
static bool check_holding_reservation(struct multipath *mpp, unsigned int *type)
665+
{
666+
if (get_be64(mpp->reservation_key) && get_prhold(mpp->alias) == PR_SET &&
667+
reservation_key_matches(mpp, (uint8_t *)&mpp->reservation_key, type) ==
668+
YNU_YES)
669+
return true;
670+
return false;
671+
}
672+
642673
static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,
643674
unsigned int rq_type,
644675
struct prout_param_descriptor * paramp, int noisy)
645676
{
646677
int i, j;
647-
int num = 0;
648678
struct pathgroup *pgp = NULL;
649679
struct path *pp = NULL;
650680
int active_pathcount = 0;
651681
pthread_attr_t attr;
652682
int rc;
653683
int count = 0;
654684
int status = MPATH_PR_SUCCESS;
655-
struct prin_resp resp = {{{.prgeneration = 0}}};
656685
bool all_threads_failed;
657-
unsigned int scope_type;
686+
unsigned int res_type;
658687

659688
if (!mpp)
660689
return MPATH_PR_DMMP_ERROR;
@@ -733,27 +762,13 @@ static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,
733762
return status;
734763
}
735764

736-
status = mpath_prin_activepath (mpp, MPATH_PRIN_RRES_SA, &resp, noisy);
737-
if (status != MPATH_PR_SUCCESS){
738-
condlog (0, "%s: pr in read reservation command failed.", mpp->wwid);
739-
return MPATH_PR_OTHER;
740-
}
741-
742-
num = resp.prin_descriptor.prin_readresv.additional_length / 8;
743-
if (num == 0){
744-
condlog (2, "%s: Path holding reservation is released.", mpp->wwid);
745-
return MPATH_PR_SUCCESS;
746-
}
747-
if (!get_be64(mpp->reservation_key) ||
748-
memcmp(&mpp->reservation_key, resp.prin_descriptor.prin_readresv.key, 8)) {
765+
if (!check_holding_reservation(mpp, &res_type)) {
749766
condlog(2, "%s: Releasing key not holding reservation.", mpp->wwid);
750767
return MPATH_PR_SUCCESS;
751768
}
752-
753-
scope_type = resp.prin_descriptor.prin_readresv.scope_type;
754-
if ((scope_type & MPATH_PR_TYPE_MASK) != rq_type) {
769+
if (res_type != rq_type) {
755770
condlog(2, "%s: --prout_type %u doesn't match reservation %u",
756-
mpp->wwid, rq_type, scope_type & MPATH_PR_TYPE_MASK);
771+
mpp->wwid, rq_type, res_type);
757772
return MPATH_PR_RESERV_CONFLICT;
758773
}
759774

@@ -773,28 +788,6 @@ static int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,
773788
return preempt_self(mpp, MPATH_PROUT_PREE_SA, rq_scope, rq_type, noisy, true);
774789
}
775790

776-
static int
777-
reservation_key_matches(struct multipath *mpp, uint8_t *key, unsigned int *type)
778-
{
779-
struct prin_resp resp = {{{.prgeneration = 0}}};
780-
int status;
781-
782-
status = mpath_prin_activepath(mpp, MPATH_PRIN_RRES_SA, &resp, 0);
783-
if (status != MPATH_PR_SUCCESS) {
784-
condlog(0, "%s: pr in read reservation command failed.", mpp->wwid);
785-
return YNU_UNDEF;
786-
}
787-
if (!resp.prin_descriptor.prin_readresv.additional_length)
788-
return YNU_NO;
789-
if (memcmp(key, resp.prin_descriptor.prin_readresv.key, 8) == 0) {
790-
if (type)
791-
*type = resp.prin_descriptor.prin_readresv.scope_type &
792-
MPATH_PR_TYPE_MASK;
793-
return YNU_YES;
794-
}
795-
return YNU_NO;
796-
}
797-
798791
/*
799792
* for MPATH_PROUT_REG_IGN_SA, we use the ignored paramp->key to store the
800793
* currently registered key for use in preempt_missing_path(), but only if
@@ -812,15 +805,6 @@ static void set_ignored_key(struct multipath *mpp, uint8_t *curr_key, uint8_t *k
812805
memcpy(key, curr_key, 8);
813806
}
814807

815-
static bool check_holding_reservation(struct multipath *mpp, unsigned int *type)
816-
{
817-
if (get_be64(mpp->reservation_key) && get_prhold(mpp->alias) == PR_SET &&
818-
reservation_key_matches(mpp, (uint8_t *)&mpp->reservation_key, type) ==
819-
YNU_YES)
820-
return true;
821-
return false;
822-
}
823-
824808
int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd,
825809
int rq_servact, int rq_scope, unsigned int rq_type,
826810
struct prout_param_descriptor *paramp, int noisy)

0 commit comments

Comments
 (0)