ZFCP HBA API Library  1
vlib_aux.h
Go to the documentation of this file.
1 /*
2  * Copyright IBM Corp. 2003,2010
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.ibm.com/developerworks/library/os-cpl.html
7  *
8  * Authors: Andreas Herrmann
9  * Stefan Voelkel
10  *
11  * File: vlib_aux.h
12  *
13  * Description:
14  * Auxiliary functions used in the library.
15  *
16  */
17 
18 #ifndef _VLIB_AUX_H_
19 #define _VLIB_AUX_H_
20 
25 #include "vlib.h"
26 
27 #define VLIB_GROW_UNITS 8
28 #define VLIB_GROW_PORTS 4
29 #define VLIB_GROW_ADAPTERS 2
30 
31 #ifdef min
32 # undef min
33 #endif
34 #define min(a, b) (((a) < (b)) ? (a) : (b))
35 
36 /*
37  * function declarations
38  */
39 
40 struct vlib_adapter *getAdapterByIndex(uint32_t);
41 struct vlib_adapter *getAdapterByHandle(HBA_HANDLE, HBA_STATUS *);
42 struct vlib_adapter *getAdapterByDevid(devid_t);
43 struct vlib_adapter *getAdapterByHostNo(unsigned short);
44 struct vlib_port *getPortByIndex(const struct vlib_adapter *, const uint32_t);
45 struct vlib_port *getPortByWWPN(const struct vlib_adapter *, const wwn_t);
46 struct vlib_unit *getUnitByIndex(const struct vlib_port *, const uint32_t);
47 struct vlib_unit *getUnitByFcLun(const struct vlib_port *, uint64_t);
48 
49 int addAdapterToRepos(struct vlib_adapter *);
50 int addPortToRepos(struct vlib_adapter *, struct vlib_port *);
51 int addUnitToRepos(struct vlib_port *, struct vlib_unit *);
52 
53 HBA_STATUS getAdapterConfig(void);
54 int getUnitsFromPort(struct vlib_port *);
55 
56 int findIndexByName(char *);
57 HBA_HANDLE openAdapterByIndex(HBA_UINT32);
58 char *getSgDevFromPort(struct vlib_port *);
59 char *getAttachedWLUN(struct vlib_adapter *, struct vlib_port *);
60 void detachWLUN(struct vlib_adapter *, struct vlib_port *);
61 
62 int revalidateAdapters(void);
63 int updateAdapter(struct vlib_adapter *adapter);
64 void doCloseAdapter(struct vlib_adapter *);
65 void closeAllAdapters(void);
66 
67 HBA_PORTTYPE vlibCharToIntPortType(char *);
68 HBA_PORTSTATE vlibCharToIntPortState(char *);
69 HBA_PORTSPEED vlibCharToIntPortSpeed(char *);
70 HBA_COS vlibCharToIntCOS(char *);
71 
72 /*
73  * inline functions
74  */
75 
81 static inline void vlib_wwn_to_HBA_WWN(uint64_t wwn, HBA_WWN *hba)
82 {
83  *((uint64_t *)(&hba->wwn)) = wwn;
84 }
85 
91 static inline void vlib_HBA_WWN_to_wwn(HBA_WWN *hba, uint64_t *wwn)
92 {
93  *wwn = *((uint64_t *)hba->wwn);
94 }
95 
101 static inline uint32_t vlib_FCID_to_hbaFCID(uint32_t fcid)
102 {
103  return fcid << 8;
104 }
105 
111 static inline uint32_t vlib_hbaFCID_to_FCID(uint32_t fcid)
112 {
113  return fcid >> 8;
114 }
115 
116 
122 static inline void invalidateAllAdapters(void)
123 {
124  unsigned int i;
125  struct vlib_adapter *adapter;
126 
127  adapter = getAdapterByIndex(0);
128  for (i = 0; i < vlib_data.adapters.used; ++i, ++adapter)
129  adapter->isInvalid = 1;
130 }
131 
138 static inline void markRepositoryInvalid(void)
139 {
141 
142  vlib_data.isValid = 0;
143 
145 }
146 
147 #endif /* _VLIB_AUX_H_ */
vlib.h
Central header file for the library.
vlib_port::wwnn
wwn_t wwnn
WWNN of the port.
Definition: vlib.h:446
vlib_adapter::ident
struct vlib_adapter_ident ident
Adapter identification.
Definition: vlib.h:476
doCloseAdapter
void doCloseAdapter(struct vlib_adapter *adapter)
Close an adapter in the repository.
Definition: vlib_aux.c:644
block_addItem
static void * block_addItem(struct block *, size_t, size_t)
Add a new item to a block.
Definition: vlib_aux.c:82
vlibCharToIntPortState
HBA_PORTSTATE vlibCharToIntPortState(char *)
Map the result of a port state string from sysfs to an int.
Definition: vlib_aux.c:713
vlib_adapter_ident::wwnn
wwn_t wwnn
WWN of adapter node.
Definition: vlib.h:459
vlib_adapter_ident::sysfsPath
char sysfsPath[PATH_MAX]
path of adapter in sysfs in the form /sys/devices/css0/0.0.0010/0.0.5923
Definition: vlib.h:469
vlib_port::host
unsigned int host
SCSI host.
Definition: vlib.h:451
vlib_port
Representation of a FC port in the library.
Definition: vlib.h:443
getAttachedWLUN
char * getAttachedWLUN(struct vlib_adapter *adapter, struct vlib_port *port)
Try to attach the report luns wlun and return its name as in "/dev".
Definition: vlib_aux.c:925
vlib_adapter::handle
HBA_HANDLE handle
Handle for this adapter.
Definition: vlib.h:477
vlib_adapter_ident::devid
devid_t devid
Unique id for adapter device.
Definition: vlib.h:458
doCloseAdapter
void doCloseAdapter(struct vlib_adapter *)
Close an adapter in the repository.
Definition: vlib_aux.c:644
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
vlib_unit
Represenation of an FCP unit in the library.
Definition: vlib.h:432
block_free
void block_free(struct block *block)
Free the array contained in a struct block.
Definition: vlib_aux.c:102
vlib_port::wwpn
wwn_t wwpn
WWPN of the port.
Definition: vlib.h:445
vlib_adapter_ident::bus_dev_name
char bus_dev_name[9]
name of device as in /sys/bus/ccw/drivers/zfcp in the form "x.x.xxxx"
Definition: vlib.h:463
vlibCharToIntCOS
HBA_COS vlibCharToIntCOS(char *)
Map the result of a class of service string to an int.
Definition: vlib_aux.c:873
vlib_adapter_ident::wwpn
wwn_t wwpn
WWN of adapter port.
Definition: vlib.h:460
vlib_port::name
char name[32]
name as in sysfs under fc_remote_ports
Definition: vlib.h:449
vlibCharToIntPortType
HBA_PORTTYPE vlibCharToIntPortType(char *)
Map the result of a port type string from sysfs to an int.
Definition: vlib_aux.c:688
getAdapterByIndex
struct vlib_adapter * getAdapterByIndex(uint32_t index)
Get an adapter by its index.
Definition: vlib_aux.c:118
REPORTLUNS_WLUN
#define REPORTLUNS_WLUN
This is the value the report luns well known lun.
Definition: vlib.h:403
addAdapterToRepos
int addAdapterToRepos(struct vlib_adapter *adapter)
Add an adapter to the repository.
Definition: vlib_aux.c:472
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
getUnitByFcLun
struct vlib_unit * getUnitByFcLun(const struct vlib_port *port, uint64_t fcLun)
Get an unit by its fclun.
Definition: vlib_aux.c:295
vlibCharToIntPortSpeed
HBA_PORTSPEED vlibCharToIntPortSpeed(char *)
Map the result of a port speed string to the HBA_PORTSPEED int.
Definition: vlib_aux.c:810
vlib_adapter_ident::host
unsigned short host
SCSI host id of this adapter.
Definition: vlib.h:461
block::used
size_t used
number of used elements in the array
Definition: vlib.h:427
findIndexByName
int findIndexByName(char *name)
Find an adapter index by name.
Definition: vlib_aux.c:582
addPortToRepos
int addPortToRepos(struct vlib_adapter *adapter, struct vlib_port *port)
Add a port from to the repository.
Definition: vlib_aux.c:409
detachWLUN
void detachWLUN(struct vlib_adapter *adapter, struct vlib_port *port)
Try to detach lun 0.
Definition: vlib_aux.c:955
getAdapterByHandle
struct vlib_adapter * getAdapterByHandle(HBA_HANDLE handle, HBA_STATUS *status)
Get an adapter by its handle.
Definition: vlib_aux.c:143
vlibCOStoFlag
int vlibCOStoFlag(int class)
Maps the number of a class of service to its bit flag according to FC-GS-4.
Definition: vlib_aux.c:841
getAdapterByHostNo
struct vlib_adapter * getAdapterByHostNo(unsigned short host)
Get an adapter by SCSI Host number as in sysfs.
Definition: vlib_aux.c:202
getPortByIndex
struct vlib_port * getPortByIndex(const struct vlib_adapter *, const uint32_t)
Get a port by its index.
Definition: vlib_aux.c:230
vlib_adapter::isInvalid
unsigned int isInvalid
Adapter invalid or not.
Definition: vlib.h:475
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
addUnitToRepos
int addUnitToRepos(struct vlib_port *port, struct vlib_unit *unit)
Add a unit to the repository.
Definition: vlib_aux.c:351
findIndexByName
int findIndexByName(char *)
Find an adapter index by name.
Definition: vlib_aux.c:582
vlib_unit::isInvalid
unsigned int isInvalid
Unit invalid or not.
Definition: vlib.h:433
getPortFromRepos
static struct vlib_port * getPortFromRepos(struct vlib_adapter *adapter, char *sysfs_name)
Check if a port specified is already stored in the repository.
Definition: vlib_aux.c:381
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_MUTEX_LOCK
#define VLIB_MUTEX_LOCK(mutex)
To lock a mutex, this macro is used, which checks for errors.
Definition: vlib.h:571
getPortByIndex
struct vlib_port * getPortByIndex(const struct vlib_adapter *adapter, const uint32_t index)
Get a port by its index.
Definition: vlib_aux.c:230
sysfs_getUnitsFromPort
int sysfs_getUnitsFromPort(struct vlib_port *port)
Get unit configuration information for a port.
Definition: vlib_sysfs.c:310
getUnitByFcLun
struct vlib_unit * getUnitByFcLun(const struct vlib_port *, uint64_t)
Get an unit by its fclun.
Definition: vlib_aux.c:295
vlib_data
Primary data structure used in the library.
Definition: vlib.h:484
vlib_port::target
unsigned int target
SCSI id.
Definition: vlib.h:453
vlib_adapter
Represenation of an adapter in the library.
Definition: vlib.h:474
vlib_data::mutex
pthread_mutex_t mutex
Protects this structure.
Definition: vlib.h:499
closeAllAdapters
void closeAllAdapters(void)
Close all adapters in the repository.
Definition: vlib_aux.c:669
getAdapterByIndex
struct vlib_adapter * getAdapterByIndex(uint32_t)
Get an adapter by its index.
Definition: vlib_aux.c:118
vlibCharToIntCOS
HBA_COS vlibCharToIntCOS(char *s)
Map the result of a class of service string to an int.
Definition: vlib_aux.c:873
addAdapterToRepos
int addAdapterToRepos(struct vlib_adapter *)
Add an adapter to the repository.
Definition: vlib_aux.c:472
revalidateUnits
static int revalidateUnits(struct vlib_port *port)
Revalidate units of an adapter and port in the repository.
Definition: vlib_sysfs.h:103
updateAdapter
int updateAdapter(struct vlib_adapter *adapter)
Update information about ports and units of an adapter.
Definition: vlib_aux.c:512
vlib_unit::fcLun
uint64_t fcLun
FCP LUN.
Definition: vlib.h:438
vlib_unit::host
unsigned int host
SCSI host.
Definition: vlib.h:434
vlib_port::did
fc_id_t did
FC did of the port.
Definition: vlib.h:447
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
vlib_unit::channel
unsigned int channel
SCSI channel.
Definition: vlib.h:435
block_assertSize
static int block_assertSize(struct block *, const size_t, const size_t, const size_t)
Assert that there is space for at least num elements in the block.
Definition: vlib_aux.c:43
getAdapterByHostNo
struct vlib_adapter * getAdapterByHostNo(unsigned short)
Get an adapter by SCSI Host number as in sysfs.
Definition: vlib_aux.c:202
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
VLIB_MUTEX_UNLOCK
#define VLIB_MUTEX_UNLOCK(mutex)
To unlock a mutex, this macro is used, which checks for errors.
Definition: vlib.h:594
block
Block structure used to hold all needed data for growable arrays.
Definition: vlib.h:425
updateAdapter
int updateAdapter(struct vlib_adapter *adapter)
Update information about ports and units of an adapter.
Definition: vlib_aux.c:512
vlib_unit::sg_dev
char sg_dev[16]
name of sg device
Definition: vlib.h:439
revalidateAdapters
int revalidateAdapters(void)
Revalidate adapters in the repository.
Definition: vlib_aux.c:546
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
sysfs_createAndReadConfigPorts
HBA_STATUS sysfs_createAndReadConfigPorts(struct vlib_adapter *adapter)
Read and store all discovered ports of an adapter.
Definition: vlib_sysfs.c:226
openAdapterByIndex
HBA_HANDLE openAdapterByIndex(HBA_UINT32 index)
Open an adapter by index.
Definition: vlib_aux.c:614
vlib_port::isInvalid
unsigned int isInvalid
Port invalid or not.
Definition: vlib.h:444
vlib_adapter_ident::class_dev_name
char class_dev_name[9]
name of device as in /sys/class/fc_host in the form "hostxxxx"
Definition: vlib.h:466
getSgDevFromPort
char * getSgDevFromPort(struct vlib_port *port)
Get the first sg device from an adapter.
Definition: vlib_aux.c:901
getAdapterByDevid
struct vlib_adapter * getAdapterByDevid(devid_t)
Get an adapter by its devid.
Definition: vlib_aux.c:176
block::data
void * data
pointer to an array
Definition: vlib.h:426
vlibCharToIntPortType
HBA_PORTTYPE vlibCharToIntPortType(char *portType)
Map the result of a port type string from sysfs to an int.
Definition: vlib_aux.c:688
getPortByWWPN
struct vlib_port * getPortByWWPN(const struct vlib_adapter *, const wwn_t)
Get a port by its WWPN.
Definition: vlib_aux.c:249
getUnitByIndex
struct vlib_unit * getUnitByIndex(const struct vlib_port *, const uint32_t)
Get an unit by its index.
Definition: vlib_aux.c:276
vlibCharToIntPortSpeed
HBA_PORTSPEED vlibCharToIntPortSpeed(char *pS)
Map the result of a port speed string to the HBA_PORTSPEED int.
Definition: vlib_aux.c:810
vlib_port::units
struct block units
List of units.
Definition: vlib.h:448
getAdapterByHandle
struct vlib_adapter * getAdapterByHandle(HBA_HANDLE, HBA_STATUS *)
Get an adapter by its handle.
Definition: vlib_aux.c:143
VLIB_ADAPTERNAME_LEN
#define VLIB_ADAPTERNAME_LEN
Maximal lenght of an adapter name as used in this libary.
Definition: vlib.h:397
revalidateAdapters
int revalidateAdapters(void)
Revalidate adapters in the repository.
Definition: vlib_aux.c:546
getUnitByIndex
struct vlib_unit * getUnitByIndex(const struct vlib_port *port, const uint32_t index)
Get an unit by its index.
Definition: vlib_aux.c:276
VLIB_PERROR
#define VLIB_PERROR(errnum, fmt, args...)
To log errors in the library, this macro is used which invokes vlib_print_error().
Definition: vlib.h:538
vlibCharToIntPortState
HBA_PORTSTATE vlibCharToIntPortState(char *portState)
Map the result of a port state string from sysfs to an int.
Definition: vlib_aux.c:713
detachWLUN
void detachWLUN(struct vlib_adapter *, struct vlib_port *)
Try to detach lun 0.
Definition: vlib_aux.c:955
addUnitToRepos
int addUnitToRepos(struct vlib_port *, struct vlib_unit *)
Add a unit to the repository.
Definition: vlib_aux.c:351
getAdapterByDevid
struct vlib_adapter * getAdapterByDevid(devid_t devid)
Get an adapter by its devid.
Definition: vlib_aux.c:176
getAdapterFromRepos
static struct vlib_adapter * getAdapterFromRepos(char *bus_dev_name)
Check if an adapter specified in an event is already stored in the repository.
Definition: vlib_aux.c:446
openAdapterByIndex
HBA_HANDLE openAdapterByIndex(HBA_UINT32)
Open an adapter by index.
Definition: vlib_aux.c:614
closeAllAdapters
void closeAllAdapters(void)
Close all adapters in the repository.
Definition: vlib_aux.c:669
vlib_port::channel
unsigned int channel
SCSI channel.
Definition: vlib.h:452
block::allocated
size_t allocated
total number of elements in the array
Definition: vlib.h:428
VLIB_INVALID_HANDLE
#define VLIB_INVALID_HANDLE
This is the value of an invalid handle as used in this library.
Definition: vlib.h:400
getUnitFromRepos
static struct vlib_unit * getUnitFromRepos(struct vlib_port *port, struct vlib_unit *unit)
Check if an unit specified in an unit event is already stored in the repository.
Definition: vlib_aux.c:322
addPortToRepos
int addPortToRepos(struct vlib_adapter *, struct vlib_port *)
Add a port from to the repository.
Definition: vlib_aux.c:409
vlib_unit::target
unsigned int target
SCSI id.
Definition: vlib.h:436
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
getSgDevFromPort
char * getSgDevFromPort(struct vlib_port *)
Get the first sg device from an adapter.
Definition: vlib_aux.c:901
VLIB_ADAPTERNAME_PREFIX
#define VLIB_ADAPTERNAME_PREFIX
Prefix used to concatednate an adapter name.
Definition: vlib.h:394
vlib_adapter::ports
struct block ports
List of ports.
Definition: vlib.h:478
vlibIntToSymbolPortSpeed
HBA_PORTSPEED vlibIntToSymbolPortSpeed(int speed)
Maps the result of a port speed int to the HBA_PORTSPEED int.
Definition: vlib_aux.c:760
invalidateAllAdapters
static void invalidateAllAdapters(void)
Mark all adapters in repository as invalid.
Definition: vlib_aux.h:122
getPortByWWPN
struct vlib_port * getPortByWWPN(const struct vlib_adapter *adapter, const wwn_t wwpn)
Get a port by its WWPN.
Definition: vlib_aux.c:249