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 | 22 ++++++++++++++++++++++
 iprlib.h |  4 ++++
 2 files changed, 26 insertions(+)

diff --git a/iprlib.c b/iprlib.c
index b03c995..7b9536c 100644
--- a/iprlib.c
+++ b/iprlib.c
@@ -44,6 +44,9 @@ static int ipr_force_uevents = 0;
 static char *hotplug_dir = NULL;
 static struct scsi_dev_data *scsi_dev_table = NULL;
 
+/* Current state of this machine. */
+enum system_p_mode power_cur_mode = POWER_BAREMETAL;
+
 /* This table includes both unsupported 522 disks and disks that support 
  being formatted to 522, but require a minimum microcode level. The disks
  that require a minimum level of microcode will be marked by the 
@@ -2068,6 +2071,23 @@ static void ipr_get_pci_slots()
 }
 
 /**
+ * load_system_p_oper_mode
+ *
+ * Discover and load current operating mode.
+ **/
+void load_system_p_oper_mode()
+{
+       struct stat st;
+
+       if (stat("/proc/ppc64/lparcfg", &st) == 0)
+               power_cur_mode = POWER_VM;
+       else if (stat("/etc/ibm_powerkvm-release", &st) == 0)
+               power_cur_mode = POWER_KVM;
+       else
+               power_cur_mode = POWER_BAREMETAL;
+}
+
+/**
  * tool_init -
  * @save_state:                integer flag - whether or not to save the old 
config
  *
@@ -2175,6 +2195,8 @@ static int __tool_init(int save_state)
        }
        closedir(dirfd);
 
+       load_system_p_oper_mode();
+
        if (!save_state)
                free_old_config();
 
diff --git a/iprlib.h b/iprlib.h
index 736d9d6..9ac523c 100644
--- a/iprlib.h
+++ b/iprlib.h
@@ -237,6 +237,9 @@ 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} ;
+
 #define  IPR_IS_DASD_DEVICE(std_inq_data) \
 ((((std_inq_data).peri_dev_type) == TYPE_DISK) && 
!((std_inq_data).removeable_medium))
 
@@ -274,6 +277,7 @@ extern int format_done;
 extern char *tool_name;
 extern struct sysfs_dev *head_zdev;
 extern struct sysfs_dev *tail_zdev;
+extern enum system_p_mode power_cur_mode;
 
 struct sysfs_dev {
        char sysfs_device_name[PATH_MAX];
-- 
2.1.0


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

Reply via email to