Query some files in rootfs to discover whether we are in a PowerVM,
powerKVM or a Power Bare Metal system.

Signed-off-by: Gabriel Krisman Bertazi <kris...@linux.vnet.ibm.com>
---
 iprlib.c | 24 ++++++++++++++++++++++++
 iprlib.h |  6 ++++++
 2 files changed, 30 insertions(+)

diff --git a/iprlib.c b/iprlib.c
index b03c995..0fdc94a 100644
--- a/iprlib.c
+++ b/iprlib.c
@@ -2068,6 +2068,28 @@ static void ipr_get_pci_slots()
 }
 
 /**
+ * get_system_p_oper_mode
+ *
+ * Discover and load current operating mode.
+ **/
+void get_system_p_oper_mode()
+{
+       struct stat st;
+
+       if (stat("/proc/ppc64/lparcfg", &st) == 0) {
+               power_cur_mode = POWER_VM;
+               return;
+       }
+
+       if (stat("/etc/ibm_powerkvm-release", &st) == 0) {
+               power_cur_mode = POWER_KVM;
+               return;
+       }
+
+       power_cur_mode = POWER_BAREMETAL;
+}
+
+/**
  * tool_init -
  * @save_state:                integer flag - whether or not to save the old 
config
  *
@@ -2175,6 +2197,8 @@ static int __tool_init(int save_state)
        }
        closedir(dirfd);
 
+       get_system_p_oper_mode();
+
        if (!save_state)
                free_old_config();
 
diff --git a/iprlib.h b/iprlib.h
index 7bd0172..33ab390 100644
--- a/iprlib.h
+++ b/iprlib.h
@@ -237,6 +237,12 @@ typedef uint64_t u64;
 /* Device write cache policies. */
 enum {IPR_DEV_CACHE_WRITE_THROUGH = 0, IPR_DEV_CACHE_WRITE_BACK};
 
+/* System P Operating modes */
+enum system_p_mode {POWER_VM, POWER_KVM, POWER_BAREMETAL} ;
+
+/* Current state of this machine. */
+enum system_p_mode power_cur_mode;
+
 #define  IPR_IS_DASD_DEVICE(std_inq_data) \
 ((((std_inq_data).peri_dev_type) == TYPE_DISK) && 
!((std_inq_data).removeable_medium))
 
-- 
2.1.0


------------------------------------------------------------------------------
_______________________________________________
Iprdd-devel mailing list
Iprdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iprdd-devel

Reply via email to