aboutsummaryrefslogtreecommitdiffstats
path: root/tools/hv
diff options
context:
space:
mode:
authorK. Y. Srinivasan <kys@microsoft.com>2012-08-13 13:06:52 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-16 16:48:08 -0400
commitb47a81dcc5a806efb6d970608299129771588289 (patch)
tree59325254754b37e1b28393c552a854e4c922e243 /tools/hv
parent9b5957803cb444a99275355eb2309b6fecc63c5f (diff)
Drivers: hv: kvp: Cleanup error handling in KVP
In preparation to implementing IP injection, cleanup the way we propagate and handle errors both in the driver as well as in the user level daemon. Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com> Reviewed-by: Olaf Hering <olaf@aepfle.de> Reviewed-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/hv')
-rw-r--r--tools/hv/hv_kvp_daemon.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 8fbcf7b3c69d..069e2b38decb 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -71,13 +71,14 @@ enum key_index {
71static char kvp_send_buffer[4096]; 71static char kvp_send_buffer[4096];
72static char kvp_recv_buffer[4096 * 2]; 72static char kvp_recv_buffer[4096 * 2];
73static struct sockaddr_nl addr; 73static struct sockaddr_nl addr;
74static int in_hand_shake = 1;
74 75
75static char *os_name = ""; 76static char *os_name = "";
76static char *os_major = ""; 77static char *os_major = "";
77static char *os_minor = ""; 78static char *os_minor = "";
78static char *processor_arch; 79static char *processor_arch;
79static char *os_build; 80static char *os_build;
80static char *lic_version; 81static char *lic_version = "Unknown version";
81static struct utsname uts_buf; 82static struct utsname uts_buf;
82 83
83 84
@@ -394,7 +395,7 @@ static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value,
394 return 1; 395 return 1;
395} 396}
396 397
397static void kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size, 398static int kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size,
398 __u8 *value, int value_size) 399 __u8 *value, int value_size)
399{ 400{
400 struct kvp_record *record; 401 struct kvp_record *record;
@@ -406,16 +407,12 @@ static void kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size,
406 record = kvp_file_info[pool].records; 407 record = kvp_file_info[pool].records;
407 408
408 if (index >= kvp_file_info[pool].num_records) { 409 if (index >= kvp_file_info[pool].num_records) {
409 /* 410 return 1;
410 * This is an invalid index; terminate enumeration;
411 * - a NULL value will do the trick.
412 */
413 strcpy(value, "");
414 return;
415 } 411 }
416 412
417 memcpy(key, record[index].key, key_size); 413 memcpy(key, record[index].key, key_size);
418 memcpy(value, record[index].value, value_size); 414 memcpy(value, record[index].value, value_size);
415 return 0;
419} 416}
420 417
421 418
@@ -646,6 +643,8 @@ int main(void)
646 char *p; 643 char *p;
647 char *key_value; 644 char *key_value;
648 char *key_name; 645 char *key_name;
646 int op;
647 int pool;
649 648
650 daemon(1, 0); 649 daemon(1, 0);
651 openlog("KVP", 0, LOG_USER); 650 openlog("KVP", 0, LOG_USER);
@@ -687,7 +686,7 @@ int main(void)
687 message->id.val = CN_KVP_VAL; 686 message->id.val = CN_KVP_VAL;
688 687
689 hv_msg = (struct hv_kvp_msg *)message->data; 688 hv_msg = (struct hv_kvp_msg *)message->data;
690 hv_msg->kvp_hdr.operation = KVP_OP_REGISTER; 689 hv_msg->kvp_hdr.operation = KVP_OP_REGISTER1;
691 message->ack = 0; 690 message->ack = 0;
692 message->len = sizeof(struct hv_kvp_msg); 691 message->len = sizeof(struct hv_kvp_msg);
693 692
@@ -721,12 +720,21 @@ int main(void)
721 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg); 720 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
722 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; 721 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data;
723 722
724 switch (hv_msg->kvp_hdr.operation) { 723 /*
725 case KVP_OP_REGISTER: 724 * We will use the KVP header information to pass back
725 * the error from this daemon. So, first copy the state
726 * and set the error code to success.
727 */
728 op = hv_msg->kvp_hdr.operation;
729 pool = hv_msg->kvp_hdr.pool;
730 hv_msg->error = HV_S_OK;
731
732 if ((in_hand_shake) && (op == KVP_OP_REGISTER1)) {
726 /* 733 /*
727 * Driver is registering with us; stash away the version 734 * Driver is registering with us; stash away the version
728 * information. 735 * information.
729 */ 736 */
737 in_hand_shake = 0;
730 p = (char *)hv_msg->body.kvp_register.version; 738 p = (char *)hv_msg->body.kvp_register.version;
731 lic_version = malloc(strlen(p) + 1); 739 lic_version = malloc(strlen(p) + 1);
732 if (lic_version) { 740 if (lic_version) {
@@ -737,44 +745,39 @@ int main(void)
737 syslog(LOG_ERR, "malloc failed"); 745 syslog(LOG_ERR, "malloc failed");
738 } 746 }
739 continue; 747 continue;
748 }
740 749
741 /* 750 switch (op) {
742 * The current protocol with the kernel component uses a
743 * NULL key name to pass an error condition.
744 * For the SET, GET and DELETE operations,
745 * use the existing protocol to pass back error.
746 */
747
748 case KVP_OP_SET: 751 case KVP_OP_SET:
749 if (kvp_key_add_or_modify(hv_msg->kvp_hdr.pool, 752 if (kvp_key_add_or_modify(pool,
750 hv_msg->body.kvp_set.data.key, 753 hv_msg->body.kvp_set.data.key,
751 hv_msg->body.kvp_set.data.key_size, 754 hv_msg->body.kvp_set.data.key_size,
752 hv_msg->body.kvp_set.data.value, 755 hv_msg->body.kvp_set.data.value,
753 hv_msg->body.kvp_set.data.value_size)) 756 hv_msg->body.kvp_set.data.value_size))
754 strcpy(hv_msg->body.kvp_set.data.key, ""); 757 hv_msg->error = HV_S_CONT;
755 break; 758 break;
756 759
757 case KVP_OP_GET: 760 case KVP_OP_GET:
758 if (kvp_get_value(hv_msg->kvp_hdr.pool, 761 if (kvp_get_value(pool,
759 hv_msg->body.kvp_set.data.key, 762 hv_msg->body.kvp_set.data.key,
760 hv_msg->body.kvp_set.data.key_size, 763 hv_msg->body.kvp_set.data.key_size,
761 hv_msg->body.kvp_set.data.value, 764 hv_msg->body.kvp_set.data.value,
762 hv_msg->body.kvp_set.data.value_size)) 765 hv_msg->body.kvp_set.data.value_size))
763 strcpy(hv_msg->body.kvp_set.data.key, ""); 766 hv_msg->error = HV_S_CONT;
764 break; 767 break;
765 768
766 case KVP_OP_DELETE: 769 case KVP_OP_DELETE:
767 if (kvp_key_delete(hv_msg->kvp_hdr.pool, 770 if (kvp_key_delete(pool,
768 hv_msg->body.kvp_delete.key, 771 hv_msg->body.kvp_delete.key,
769 hv_msg->body.kvp_delete.key_size)) 772 hv_msg->body.kvp_delete.key_size))
770 strcpy(hv_msg->body.kvp_delete.key, ""); 773 hv_msg->error = HV_S_CONT;
771 break; 774 break;
772 775
773 default: 776 default:
774 break; 777 break;
775 } 778 }
776 779
777 if (hv_msg->kvp_hdr.operation != KVP_OP_ENUMERATE) 780 if (op != KVP_OP_ENUMERATE)
778 goto kvp_done; 781 goto kvp_done;
779 782
780 /* 783 /*
@@ -782,13 +785,14 @@ int main(void)
782 * both the key and the value; if not read from the 785 * both the key and the value; if not read from the
783 * appropriate pool. 786 * appropriate pool.
784 */ 787 */
785 if (hv_msg->kvp_hdr.pool != KVP_POOL_AUTO) { 788 if (pool != KVP_POOL_AUTO) {
786 kvp_pool_enumerate(hv_msg->kvp_hdr.pool, 789 if (kvp_pool_enumerate(pool,
787 hv_msg->body.kvp_enum_data.index, 790 hv_msg->body.kvp_enum_data.index,
788 hv_msg->body.kvp_enum_data.data.key, 791 hv_msg->body.kvp_enum_data.data.key,
789 HV_KVP_EXCHANGE_MAX_KEY_SIZE, 792 HV_KVP_EXCHANGE_MAX_KEY_SIZE,
790 hv_msg->body.kvp_enum_data.data.value, 793 hv_msg->body.kvp_enum_data.data.value,
791 HV_KVP_EXCHANGE_MAX_VALUE_SIZE); 794 HV_KVP_EXCHANGE_MAX_VALUE_SIZE))
795 hv_msg->error = HV_S_CONT;
792 goto kvp_done; 796 goto kvp_done;
793 } 797 }
794 798
@@ -841,11 +845,7 @@ int main(void)
841 strcpy(key_name, "ProcessorArchitecture"); 845 strcpy(key_name, "ProcessorArchitecture");
842 break; 846 break;
843 default: 847 default:
844 strcpy(key_value, "Unknown Key"); 848 hv_msg->error = HV_S_CONT;
845 /*
846 * We use a null key name to terminate enumeration.
847 */
848 strcpy(key_name, "");
849 break; 849 break;
850 } 850 }
851 /* 851 /*