Recognize errors returned in MANAGEMENT_ERROR_STATUS TLV and return
a distinct value from run_pmc in case such error is received.

Signed-off-by: Jiri Benc <jb...@redhat.com>
---
 phc2sys.c |   34 +++++++++++++++++++++++++++-------
 1 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/phc2sys.c b/phc2sys.c
index f7af1b26451b..731c2bb1af35 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -521,9 +521,11 @@ static int is_msg_mgt(struct ptp_message *msg)
        if (msg->tlv_count != 1)
                return 0;
        tlv = (struct TLV *) msg->management.suffix;
-       if (tlv->type != TLV_MANAGEMENT)
-               return 0;
-       return 1;
+       if (tlv->type == TLV_MANAGEMENT)
+               return 1;
+       if (tlv->type == TLV_MANAGEMENT_ERROR_STATUS)
+               return -1;
+       return 0;
 }
 
 static int get_mgt_id(struct ptp_message *msg)
@@ -538,6 +540,14 @@ static void *get_mgt_data(struct ptp_message *msg)
        return mgt->data;
 }
 
+static int get_mgt_err_id(struct ptp_message *msg)
+{
+       struct management_error_status *mgt;
+
+       mgt = (struct management_error_status *)msg->management.suffix;
+       return mgt->id;
+}
+
 static int normalize_state(int state)
 {
        if (state != PS_MASTER && state != PS_SLAVE &&
@@ -625,12 +635,18 @@ static int init_pmc(struct node *node, int domain_number)
        return 0;
 }
 
+/* Return values:
+ * 1: success
+ * 0: timeout
+ * -1: error reported by the other side
+ * -2: local error, fatal
+ */
 static int run_pmc(struct node *node, int timeout, int ds_id,
                   struct ptp_message **msg)
 {
 #define N_FD 1
        struct pollfd pollfd[N_FD];
-       int cnt;
+       int cnt, res;
 
        while (1) {
                pollfd[0].fd = pmc_get_transport_fd(node->pmc);
@@ -641,7 +657,7 @@ static int run_pmc(struct node *node, int timeout, int 
ds_id,
                cnt = poll(pollfd, N_FD, timeout);
                if (cnt < 0) {
                        pr_err("poll failed");
-                       return -1;
+                       return -2;
                }
                if (!cnt) {
                        /* Request the data set again in the next run. */
@@ -671,8 +687,12 @@ static int run_pmc(struct node *node, int timeout, int 
ds_id,
                if (!*msg)
                        continue;
 
-               if (!is_msg_mgt(*msg) ||
-                   recv_subscribed(node, *msg, ds_id) ||
+               res = is_msg_mgt(*msg);
+               if (res < 0 && get_mgt_err_id(*msg) == ds_id) {
+                       node->pmc_ds_requested = 0;
+                       return -1;
+               }
+               if (res <= 0 || recv_subscribed(node, *msg, ds_id) ||
                    get_mgt_id(*msg) != ds_id) {
                        msg_put(*msg);
                        *msg = NULL;
-- 
1.7.6.5


------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to