2009-06-02 15:12:53 +00:00
|
|
|
/*
|
2013-01-07 17:05:31 +00: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-07 17:05:31 +00: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 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00: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 16:13:45 +00:00
|
|
|
#include <stdlib.h>
|
2009-06-02 15:12:53 +00:00
|
|
|
|
2009-09-15 17:30:17 +00: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 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2013-04-03 10:36:23 +00: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-07 17:05:31 +00:00
|
|
|
int
|
2013-05-03 06:03:26 +00:00
|
|
|
detect_scsi_host_caps(union _virNodeDevCapData *d)
|
2009-06-26 14:09:01 +00:00
|
|
|
{
|
2013-01-07 17:05:32 +00:00
|
|
|
char *max_vports = NULL;
|
|
|
|
char *vports = NULL;
|
2013-01-07 17:05:31 +00:00
|
|
|
int ret = -1;
|
2009-06-02 15:12:53 +00:00
|
|
|
|
2010-05-20 06:57:06 +00: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 12:45:14 +00:00
|
|
|
if (virIsCapableFCHost(NULL, d->scsi_host.host)) {
|
2013-01-07 17:05:31 +00:00
|
|
|
d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
|
|
|
|
|
|
|
|
if (virReadFCHost(NULL,
|
|
|
|
d->scsi_host.host,
|
|
|
|
"port_name",
|
2013-01-07 17:05:32 +00:00
|
|
|
&d->scsi_host.wwpn) < 0) {
|
2013-01-07 17:05:31 +00:00
|
|
|
VIR_ERROR(_("Failed to read WWPN for host%d"), d->scsi_host.host);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virReadFCHost(NULL,
|
|
|
|
d->scsi_host.host,
|
|
|
|
"node_name",
|
2013-01-07 17:05:32 +00:00
|
|
|
&d->scsi_host.wwnn) < 0) {
|
2013-01-07 17:05:31 +00:00
|
|
|
VIR_ERROR(_("Failed to read WWNN for host%d"), d->scsi_host.host);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virReadFCHost(NULL,
|
|
|
|
d->scsi_host.host,
|
|
|
|
"fabric_name",
|
2013-01-07 17:05:32 +00:00
|
|
|
&d->scsi_host.fabric_wwn) < 0) {
|
2013-01-07 17:05:31 +00:00
|
|
|
VIR_ERROR(_("Failed to read fabric WWN for host%d"),
|
|
|
|
d->scsi_host.host);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
|
|
|
|
2013-05-06 12:45:14 +00:00
|
|
|
if (virIsCapableVport(NULL, d->scsi_host.host)) {
|
2013-01-07 17:05:31 +00:00
|
|
|
d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
|
2011-12-06 12:09:03 +00:00
|
|
|
|
2013-01-07 17:05:32 +00:00
|
|
|
if (virReadFCHost(NULL,
|
2013-06-12 08:30:13 +00:00
|
|
|
d->scsi_host.host,
|
2013-01-07 17:05:32 +00:00
|
|
|
"max_npiv_vports",
|
|
|
|
&max_vports) < 0) {
|
|
|
|
VIR_ERROR(_("Failed to read max_npiv_vports for host%d"),
|
|
|
|
d->scsi_host.host);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virReadFCHost(NULL,
|
2013-06-12 08:30:13 +00:00
|
|
|
d->scsi_host.host,
|
2013-01-07 17:05:32 +00:00
|
|
|
"npiv_vports_inuse",
|
|
|
|
&vports) < 0) {
|
|
|
|
VIR_ERROR(_("Failed to read npiv_vports_inuse for host%d"),
|
|
|
|
d->scsi_host.host);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrToLong_i(max_vports, NULL, 10,
|
|
|
|
&d->scsi_host.max_vports) < 0) {
|
|
|
|
VIR_ERROR(_("Failed to parse value of max_npiv_vports '%s'"),
|
|
|
|
max_vports);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrToLong_i(vports, NULL, 10,
|
|
|
|
&d->scsi_host.vports) < 0) {
|
|
|
|
VIR_ERROR(_("Failed to parse value of npiv_vports_inuse '%s'"),
|
|
|
|
vports);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-07 17:05:31 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2013-01-07 17:05:31 +00:00
|
|
|
if (ret < 0) {
|
2013-01-07 17:05:32 +00: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 12:09:03 +00:00
|
|
|
VIR_FREE(d->scsi_host.fabric_wwn);
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
2013-01-07 17:05:32 +00:00
|
|
|
VIR_FREE(max_vports);
|
|
|
|
VIR_FREE(vports);
|
2013-01-07 17:05:31 +00:00
|
|
|
return ret;
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 06:03:26 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
int
|
|
|
|
detect_scsi_host_caps(union _virNodeDevCapData *d ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:12:53 +00:00
|
|
|
#endif /* __linux__ */
|