2009-06-02 15:12:53 +00:00
|
|
|
/*
|
|
|
|
* node_device_hal_linuc.c: Linux specific code to gather device data
|
|
|
|
* not available through HAL.
|
|
|
|
*
|
2011-11-07 17:47:31 +00:00
|
|
|
* Copyright (C) 2009-2011 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"
|
2009-06-02 15:12:53 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NODEDEV
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
2009-06-26 14:09:01 +00:00
|
|
|
int check_fc_host_linux(union _virNodeDevCapData *d)
|
|
|
|
{
|
|
|
|
char *sysfs_path = NULL;
|
|
|
|
int retval = 0;
|
|
|
|
struct stat st;
|
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
|
|
|
|
2010-08-17 15:21:16 +00:00
|
|
|
if (virAsprintf(&sysfs_path, "%shost%d",
|
2009-06-26 14:09:01 +00:00
|
|
|
LINUX_SYSFS_FC_HOST_PREFIX,
|
|
|
|
d->scsi_host.host) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-06-02 15:12:53 +00:00
|
|
|
retval = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-06-26 14:09:01 +00:00
|
|
|
if (stat(sysfs_path, &st) != 0) {
|
|
|
|
/* Not an FC HBA; not an error, either. */
|
2009-06-02 15:12:53 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-06-26 14:09:01 +00:00
|
|
|
d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
|
2009-06-02 15:12:53 +00:00
|
|
|
|
2013-01-07 17:05:29 +00:00
|
|
|
if (virReadFCHost(NULL,
|
|
|
|
d->scsi_host.host,
|
|
|
|
"port_name",
|
|
|
|
&d->scsi_host.wwpn) == -1) {
|
2009-06-26 14:09:01 +00:00
|
|
|
VIR_ERROR(_("Failed to read WWPN for host%d"),
|
|
|
|
d->scsi_host.host);
|
2009-06-02 15:12:53 +00:00
|
|
|
retval = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-01-07 17:05:29 +00:00
|
|
|
if (virReadFCHost(NULL,
|
|
|
|
d->scsi_host.host,
|
|
|
|
"node_name",
|
|
|
|
&d->scsi_host.wwnn) == -1) {
|
2009-06-26 14:09:01 +00:00
|
|
|
VIR_ERROR(_("Failed to read WWNN for host%d"),
|
|
|
|
d->scsi_host.host);
|
|
|
|
retval = -1;
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 17:05:29 +00:00
|
|
|
if (virReadFCHost(NULL,
|
|
|
|
d->scsi_host.host,
|
|
|
|
"fabric_name",
|
|
|
|
&d->scsi_host.fabric_wwn) == -1) {
|
2011-12-06 12:09:03 +00:00
|
|
|
VIR_ERROR(_("Failed to read fabric WWN for host%d"),
|
|
|
|
d->scsi_host.host);
|
|
|
|
retval = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:12:53 +00:00
|
|
|
out:
|
2009-06-26 14:09:01 +00:00
|
|
|
if (retval == -1) {
|
|
|
|
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
|
|
|
}
|
|
|
|
VIR_FREE(sysfs_path);
|
2011-07-05 21:57:14 +00:00
|
|
|
return retval;
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int check_vport_capable_linux(union _virNodeDevCapData *d)
|
|
|
|
{
|
|
|
|
char *sysfs_path = NULL;
|
|
|
|
struct stat st;
|
|
|
|
int retval = 0;
|
|
|
|
|
2010-08-17 15:21:16 +00:00
|
|
|
if (virAsprintf(&sysfs_path,
|
|
|
|
"%shost%d%s",
|
2009-06-02 15:12:53 +00:00
|
|
|
LINUX_SYSFS_FC_HOST_PREFIX,
|
2010-08-17 15:21:16 +00:00
|
|
|
d->scsi_host.host,
|
|
|
|
LINUX_SYSFS_VPORT_CREATE_POSTFIX) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-06-02 15:12:53 +00:00
|
|
|
retval = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-08-17 15:21:16 +00:00
|
|
|
if (stat(sysfs_path, &st) == 0) {
|
|
|
|
d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
|
2009-06-02 15:12:53 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-08-17 15:21:16 +00:00
|
|
|
VIR_FREE(sysfs_path);
|
|
|
|
if (virAsprintf(&sysfs_path,
|
|
|
|
"%shost%d%s",
|
|
|
|
LINUX_SYSFS_SCSI_HOST_PREFIX,
|
|
|
|
d->scsi_host.host,
|
|
|
|
LINUX_SYSFS_VPORT_CREATE_POSTFIX) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
retval = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat(sysfs_path, &st) == 0) {
|
|
|
|
d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
|
|
|
|
} else {
|
|
|
|
/* Not a vport capable HBA; not an error, either. */
|
|
|
|
VIR_DEBUG("No vport operation path found for host%d",
|
|
|
|
d->scsi_host.host);
|
|
|
|
}
|
2009-06-02 15:12:53 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
VIR_FREE(sysfs_path);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __linux__ */
|