2009-06-02 15:12:53 +00:00
|
|
|
/*
|
2013-01-08 01:05:31 +08:00
|
|
|
* node_device_linux_sysfs.c: Linux specific code to gather device data
|
2009-06-02 15:12:53 +00:00
|
|
|
* not available through HAL.
|
|
|
|
*
|
2013-01-08 01:05:31 +08:00
|
|
|
* Copyright (C) 2009-2013 Red Hat, Inc.
|
2009-06-02 15:12:53 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 16:30:55 -06:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 18:06:23 +08:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-06-02 15:12:53 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
2010-01-22 13:21:16 +00:00
|
|
|
#include <sys/stat.h>
|
2010-01-26 17:13:45 +01:00
|
|
|
#include <stdlib.h>
|
2009-06-02 15:12:53 +00:00
|
|
|
|
2009-09-15 18:30:17 +01:00
|
|
|
#include "node_device_driver.h"
|
2009-06-02 15:12:53 +00:00
|
|
|
#include "node_device_hal.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2011-07-19 12:32:58 -06:00
|
|
|
#include "virfile.h"
|
2013-04-03 12:36:23 +02:00
|
|
|
#include "virstring.h"
|
2009-06-02 15:12:53 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NODEDEV
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("node_device.node_device_linux_sysfs");
|
|
|
|
|
2013-01-08 01:05:31 +08:00
|
|
|
int
|
2013-05-03 08:03:26 +02:00
|
|
|
detect_scsi_host_caps(union _virNodeDevCapData *d)
|
2009-06-26 14:09:01 +00:00
|
|
|
{
|
2013-01-08 01:05:32 +08:00
|
|
|
char *max_vports = NULL;
|
|
|
|
char *vports = NULL;
|
2013-01-08 01:05:31 +08:00
|
|
|
int ret = -1;
|
2009-06-02 15:12:53 +00:00
|
|
|
|
2014-06-05 13:17:05 -04:00
|
|
|
if (virReadSCSIUniqueId(NULL, d->scsi_host.host,
|
|
|
|
&d->scsi_host.unique_id) < 0) {
|
|
|
|
VIR_DEBUG("Failed to read unique_id for host%d", d->scsi_host.host);
|
|
|
|
d->scsi_host.unique_id = -1;
|
|
|
|
}
|
|
|
|
|
2010-05-20 08:57:06 +02:00
|
|
|
VIR_DEBUG("Checking if host%d is an FC HBA", d->scsi_host.host);
|
2009-06-26 14:09:01 +00:00
|
|
|
|
2013-05-06 20:45:14 +08:00
|
|
|
if (virIsCapableFCHost(NULL, d->scsi_host.host)) {
|
2013-01-08 01:05:31 +08:00
|
|
|
d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
|
|
|
|
|
|
|
|
if (virReadFCHost(NULL,
|
|
|
|
d->scsi_host.host,
|
|
|
|
"port_name",
|
2013-01-08 01:05:32 +08:00
|
|
|
&d->scsi_host.wwpn) < 0) {
|
2014-11-04 15:12:39 +01:00
|
|
|
VIR_WARN("Failed to read WWPN for host%d", d->scsi_host.host);
|
2013-01-08 01:05:31 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virReadFCHost(NULL,
|
|
|
|
d->scsi_host.host,
|
|
|
|
"node_name",
|
2013-01-08 01:05:32 +08:00
|
|
|
&d->scsi_host.wwnn) < 0) {
|
2014-11-04 15:12:39 +01:00
|
|
|
VIR_WARN("Failed to read WWNN for host%d", d->scsi_host.host);
|
2013-01-08 01:05:31 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virReadFCHost(NULL,
|
|
|
|
d->scsi_host.host,
|
|
|
|
"fabric_name",
|
2013-01-08 01:05:32 +08:00
|
|
|
&d->scsi_host.fabric_wwn) < 0) {
|
2014-11-04 15:12:39 +01:00
|
|
|
VIR_WARN("Failed to read fabric WWN for host%d",
|
|
|
|
d->scsi_host.host);
|
2013-01-08 01:05:31 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
|
|
|
|
2013-05-06 20:45:14 +08:00
|
|
|
if (virIsCapableVport(NULL, d->scsi_host.host)) {
|
2013-01-08 01:05:31 +08:00
|
|
|
d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
|
2011-12-06 07:09:03 -05:00
|
|
|
|
2013-01-08 01:05:32 +08:00
|
|
|
if (virReadFCHost(NULL,
|
2013-06-12 10:30:13 +02:00
|
|
|
d->scsi_host.host,
|
2013-01-08 01:05:32 +08:00
|
|
|
"max_npiv_vports",
|
|
|
|
&max_vports) < 0) {
|
2014-11-04 15:12:39 +01:00
|
|
|
VIR_WARN("Failed to read max_npiv_vports for host%d",
|
|
|
|
d->scsi_host.host);
|
2013-01-08 01:05:32 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virReadFCHost(NULL,
|
2013-06-12 10:30:13 +02:00
|
|
|
d->scsi_host.host,
|
2013-01-08 01:05:32 +08:00
|
|
|
"npiv_vports_inuse",
|
|
|
|
&vports) < 0) {
|
2014-11-04 15:12:39 +01:00
|
|
|
VIR_WARN("Failed to read npiv_vports_inuse for host%d",
|
|
|
|
d->scsi_host.host);
|
2013-01-08 01:05:32 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrToLong_i(max_vports, NULL, 10,
|
|
|
|
&d->scsi_host.max_vports) < 0) {
|
2014-11-04 15:12:39 +01:00
|
|
|
VIR_WARN("Failed to parse value of max_npiv_vports '%s'",
|
2013-01-08 01:05:32 +08:00
|
|
|
max_vports);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrToLong_i(vports, NULL, 10,
|
|
|
|
&d->scsi_host.vports) < 0) {
|
2014-11-04 15:12:39 +01:00
|
|
|
VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'",
|
|
|
|
vports);
|
2013-01-08 01:05:32 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 01:05:31 +08:00
|
|
|
ret = 0;
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2013-01-08 01:05:31 +08:00
|
|
|
if (ret < 0) {
|
2013-01-08 01:05:32 +08:00
|
|
|
/* Clear the two flags in case of producing confusing XML output */
|
|
|
|
d->scsi_host.flags &= ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST |
|
|
|
|
VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS);
|
|
|
|
|
2009-06-26 14:09:01 +00:00
|
|
|
VIR_FREE(d->scsi_host.wwnn);
|
|
|
|
VIR_FREE(d->scsi_host.wwpn);
|
2011-12-06 07:09:03 -05:00
|
|
|
VIR_FREE(d->scsi_host.fabric_wwn);
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
2013-01-08 01:05:32 +08:00
|
|
|
VIR_FREE(max_vports);
|
|
|
|
VIR_FREE(vports);
|
2013-01-08 01:05:31 +08:00
|
|
|
return ret;
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 08:03:26 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
int
|
|
|
|
detect_scsi_host_caps(union _virNodeDevCapData *d ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:12:53 +00:00
|
|
|
#endif /* __linux__ */
|