vlib_aux.h
Go to the documentation of this file.
/*
* Copyright IBM Corp. 2003,2010
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.ibm.com/developerworks/library/os-cpl.html
*
* Authors: Andreas Herrmann
* Stefan Voelkel
*
* File: vlib_aux.h
*
* Description:
* Auxiliary functions used in the library.
*
*/
#ifndef _VLIB_AUX_H_
#define _VLIB_AUX_H_
#include "vlib.h"
#define VLIB_GROW_UNITS 8
#define VLIB_GROW_PORTS 4
#define VLIB_GROW_ADAPTERS 2
#ifdef min
# undef min
#endif
#define min(a, b) (((a) < (b)) ? (a) : (b))
/*
* function declarations
*/
struct vlib_adapter *getAdapterByIndex(uint32_t);
struct vlib_adapter *getAdapterByHandle(HBA_HANDLE, HBA_STATUS *);
struct vlib_adapter *getAdapterByDevid(devid_t);
struct vlib_adapter *getAdapterByHostNo(unsigned short);
struct vlib_port *getPortByIndex(const struct vlib_adapter *, const uint32_t);
struct vlib_port *getPortByWWPN(const struct vlib_adapter *, const wwn_t);
struct vlib_unit *getUnitByIndex(const struct vlib_port *, const uint32_t);
struct vlib_unit *getUnitByFcLun(const struct vlib_port *, uint64_t);
int addAdapterToRepos(struct vlib_adapter *);
int addPortToRepos(struct vlib_adapter *, struct vlib_port *);
int addUnitToRepos(struct vlib_port *, struct vlib_unit *);
HBA_STATUS getAdapterConfig(void);
int getUnitsFromPort(struct vlib_port *);
int findIndexByName(char *);
HBA_HANDLE openAdapterByIndex(HBA_UINT32);
char *getSgDevFromPort(struct vlib_port *);
char *getAttachedWLUN(struct vlib_adapter *, struct vlib_port *);
void detachWLUN(struct vlib_adapter *, struct vlib_port *);
int revalidateAdapters(void);
int updateAdapter(struct vlib_adapter *adapter);
void doCloseAdapter(struct vlib_adapter *);
void closeAllAdapters(void);
HBA_PORTTYPE vlibCharToIntPortType(char *);
HBA_PORTSTATE vlibCharToIntPortState(char *);
HBA_PORTSPEED vlibCharToIntPortSpeed(char *);
HBA_COS vlibCharToIntCOS(char *);
/*
* inline functions
*/
static inline void vlib_wwn_to_HBA_WWN(uint64_t wwn, HBA_WWN *hba)
{
*((uint64_t *)(&hba->wwn)) = wwn;
}
static inline void vlib_HBA_WWN_to_wwn(HBA_WWN *hba, uint64_t *wwn)
{
*wwn = *((uint64_t *)hba->wwn);
}
static inline uint32_t vlib_FCID_to_hbaFCID(uint32_t fcid)
{
return fcid << 8;
}
static inline uint32_t vlib_hbaFCID_to_FCID(uint32_t fcid)
{
return fcid >> 8;
}
static inline void invalidateAllAdapters(void)
{
unsigned int i;
struct vlib_adapter *adapter;
adapter = getAdapterByIndex(0);
for (i = 0; i < vlib_data.adapters.used; ++i, ++adapter)
adapter->isInvalid = 1;
}
static inline void markRepositoryInvalid(void)
{
VLIB_MUTEX_LOCK(&vlib_data.mutex);
vlib_data.isValid = 0;
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
}
#endif /* _VLIB_AUX_H_ */
block::used
size_t used
number of used elements in the array
Definition vlib.h:427
vlib_adapter
Represenation of an adapter in the library.
Definition vlib.h:474
vlib_adapter::isInvalid
unsigned int isInvalid
Adapter invalid or not.
Definition vlib.h:475
vlib_data
Primary data structure used in the library.
Definition vlib.h:484
vlib_data::mutex
pthread_mutex_t mutex
Protects this structure.
Definition vlib.h:499
vlib_data::isValid
unsigned int isValid
Repositoy valid or not This flag is set for instance if a loss of events is detected.
Definition vlib.h:487
vlib_data::adapters
struct block adapters
List of adapters In fact this is the anchor of the library's repository.
Definition vlib.h:494
vlib_port
Representation of a FC port in the library.
Definition vlib.h:443
vlib_unit
Represenation of an FCP unit in the library.
Definition vlib.h:432
vlib.h
Central header file for the library.
VLIB_MUTEX_UNLOCK
#define VLIB_MUTEX_UNLOCK(mutex)
To unlock a mutex, this macro is used, which checks for errors.
Definition vlib.h:594
VLIB_MUTEX_LOCK
#define VLIB_MUTEX_LOCK(mutex)
To lock a mutex, this macro is used, which checks for errors.
Definition vlib.h:571
vlib_HBA_WWN_to_wwn
static void vlib_HBA_WWN_to_wwn(HBA_WWN *hba, uint64_t *wwn)
Convert HBA_WWN to uint64_t – hide ill-favoured type cast.
Definition vlib_aux.h:91
getAdapterByIndex
struct vlib_adapter * getAdapterByIndex(uint32_t)
Get an adapter by its index.
Definition vlib_aux.c:118
openAdapterByIndex
HBA_HANDLE openAdapterByIndex(HBA_UINT32)
Open an adapter by index.
Definition vlib_aux.c:614
getUnitByIndex
struct vlib_unit * getUnitByIndex(const struct vlib_port *, const uint32_t)
Get an unit by its index.
Definition vlib_aux.c:276
markRepositoryInvalid
static void markRepositoryInvalid(void)
Mark repositroy of library as invalid. This is appropriate if a loss of events is detected.
Definition vlib_aux.h:138
closeAllAdapters
void closeAllAdapters(void)
Close all adapters in the repository.
Definition vlib_aux.c:669
getAdapterByHandle
struct vlib_adapter * getAdapterByHandle(HBA_HANDLE, HBA_STATUS *)
Get an adapter by its handle.
Definition vlib_aux.c:143
getAdapterByDevid
struct vlib_adapter * getAdapterByDevid(devid_t)
Get an adapter by its devid.
Definition vlib_aux.c:176
invalidateAllAdapters
static void invalidateAllAdapters(void)
Mark all adapters in repository as invalid.
Definition vlib_aux.h:122
vlib_FCID_to_hbaFCID
static uint32_t vlib_FCID_to_hbaFCID(uint32_t fcid)
Convert a FC DID to a FC-HBA PortFcId.
Definition vlib_aux.h:101
findIndexByName
int findIndexByName(char *)
Find an adapter index by name.
Definition vlib_aux.c:582
getPortByIndex
struct vlib_port * getPortByIndex(const struct vlib_adapter *, const uint32_t)
Get a port by its index.
Definition vlib_aux.c:230
addUnitToRepos
int addUnitToRepos(struct vlib_port *, struct vlib_unit *)
Add a unit to the repository.
Definition vlib_aux.c:351
getPortByWWPN
struct vlib_port * getPortByWWPN(const struct vlib_adapter *, const wwn_t)
Get a port by its WWPN.
Definition vlib_aux.c:249
vlib_hbaFCID_to_FCID
static uint32_t vlib_hbaFCID_to_FCID(uint32_t fcid)
Convert a FC-HBA PortFcId to a FC DID.
Definition vlib_aux.h:111
addPortToRepos
int addPortToRepos(struct vlib_adapter *, struct vlib_port *)
Add a port from to the repository.
Definition vlib_aux.c:409
getAdapterByHostNo
struct vlib_adapter * getAdapterByHostNo(unsigned short)
Get an adapter by SCSI Host number as in sysfs.
Definition vlib_aux.c:202
doCloseAdapter
void doCloseAdapter(struct vlib_adapter *)
Close an adapter in the repository.
Definition vlib_aux.c:644
vlibCharToIntPortSpeed
HBA_PORTSPEED vlibCharToIntPortSpeed(char *)
Map the result of a port speed string to the HBA_PORTSPEED int.
Definition vlib_aux.c:810
addAdapterToRepos
int addAdapterToRepos(struct vlib_adapter *)
Add an adapter to the repository.
Definition vlib_aux.c:472
updateAdapter
int updateAdapter(struct vlib_adapter *adapter)
Update information about ports and units of an adapter.
Definition vlib_aux.c:512
getUnitByFcLun
struct vlib_unit * getUnitByFcLun(const struct vlib_port *, uint64_t)
Get an unit by its fclun.
Definition vlib_aux.c:295
vlibCharToIntCOS
HBA_COS vlibCharToIntCOS(char *)
Map the result of a class of service string to an int.
Definition vlib_aux.c:873
getAttachedWLUN
char * getAttachedWLUN(struct vlib_adapter *, struct vlib_port *)
Try to attach the report luns wlun and return its name as in "/dev".
Definition vlib_aux.c:925
revalidateAdapters
int revalidateAdapters(void)
Revalidate adapters in the repository.
Definition vlib_aux.c:546
vlibCharToIntPortState
HBA_PORTSTATE vlibCharToIntPortState(char *)
Map the result of a port state string from sysfs to an int.
Definition vlib_aux.c:713
vlib_wwn_to_HBA_WWN
static void vlib_wwn_to_HBA_WWN(uint64_t wwn, HBA_WWN *hba)
Convert uint64_t to HBA_WWN – hide ill-favoured type cast.
Definition vlib_aux.h:81
getSgDevFromPort
char * getSgDevFromPort(struct vlib_port *)
Get the first sg device from an adapter.
Definition vlib_aux.c:901
vlibCharToIntPortType
HBA_PORTTYPE vlibCharToIntPortType(char *)
Map the result of a port type string from sysfs to an int.
Definition vlib_aux.c:688
detachWLUN
void detachWLUN(struct vlib_adapter *, struct vlib_port *)
Try to detach lun 0.
Definition vlib_aux.c:955