|
Packit |
7e09eb |
/*
|
|
Packit |
7e09eb |
* Intel(R) Enclosure LED Utilities
|
|
Packit |
7e09eb |
* Copyright (C) 2009-2018 Intel Corporation.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* This program is free software; you can redistribute it and/or modify it
|
|
Packit |
7e09eb |
* under the terms and conditions of the GNU General Public License,
|
|
Packit |
7e09eb |
* version 2, as published by the Free Software Foundation.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
Packit |
7e09eb |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
Packit |
7e09eb |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
Packit |
7e09eb |
* more details.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* You should have received a copy of the GNU General Public License along with
|
|
Packit |
7e09eb |
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit |
7e09eb |
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
#ifndef _BLOCK_H_INCLUDED_
|
|
Packit |
7e09eb |
#define _BLOCK_H_INCLUDED_
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
#include "cntrl.h"
|
|
Packit |
7e09eb |
#include "ibpi.h"
|
|
Packit |
7e09eb |
#include "time.h"
|
|
Packit |
7e09eb |
#include "list.h"
|
|
Packit |
7e09eb |
#include "raid.h"
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
struct block_device;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* @brief Pointer to a send message function.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* The pointer to a function which knows how to send LED message to a driver of
|
|
Packit |
7e09eb |
* storage controller using the given protocol.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @param[in] path path in sysfs to a host device
|
|
Packit |
7e09eb |
* @see block_device::cntrl_path.
|
|
Packit |
7e09eb |
* @param[in] ibpi an IBPI pattern (state) to visualize.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @return 1 if successful, otherwise the function returns 0.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
typedef int (*send_message_t) (struct block_device *device,
|
|
Packit |
7e09eb |
enum ibpi_pattern ibpi);
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* @brief Pointer to a flush buffer function.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @param[in] device pointer to a block device
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @return 1 if successful, otherwise the function returns 0.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
typedef int (*flush_message_t) (struct block_device *device);
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* @brief Describes a block device.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* This structure describes a block device. It does not describe virtual devices
|
|
Packit |
7e09eb |
* or partitions on physical block devices.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
struct block_device {
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* Real path in sysfs tree. This means i.e. if /sys/block/sda is symbolic link
|
|
Packit |
7e09eb |
* then the link will be read and path stored in sysfs_path field. This path
|
|
Packit |
7e09eb |
* may not exist in sysfs if connection to physical drive is lost. This filed
|
|
Packit |
7e09eb |
* cannot have NULL pointer assigned.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
char *sysfs_path;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* The pointer to a function which sends a message to driver in order to
|
|
Packit |
7e09eb |
* control LEDs in an enclosure or DAS system - @see send_message_t for details.
|
|
Packit |
7e09eb |
* This field cannot have NULL pointer assigned.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
send_message_t send_fn;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* The pointer to a function which flush buffers filled by send_fn.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
flush_message_t flush_fn;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* Canonical path to block device where enclosure management fields are located.
|
|
Packit |
7e09eb |
* This path is always accessible even if the connection to physical device
|
|
Packit |
7e09eb |
* is lost. In case of AHCI controller it points to SATA phy. In case of SAS
|
|
Packit |
7e09eb |
* this path points to SES entry associated with the slot in an enclosure.
|
|
Packit |
7e09eb |
* This field cannot have NULL pointer assign.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
char *cntrl_path;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* The current state of block device. This is an IBPI pattern and it is used
|
|
Packit |
7e09eb |
* to visualize the state of block device.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
enum ibpi_pattern ibpi;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* The previous state of block device.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
enum ibpi_pattern ibpi_prev;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* The time stamp used to determine if the given block device still exist or
|
|
Packit |
7e09eb |
* it failed and the device is no longer available. Every time IBPI pattern
|
|
Packit |
7e09eb |
* is updated, the time-stamp is updated, too.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
time_t timestamp;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* The pointer to storage controller structure the device is connected to.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
struct cntrl_device *cntrl;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
struct _host_type *host;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
int host_id;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* The index of phy utilized by directly attached to controller block device.
|
|
Packit |
7e09eb |
* It is meaningful if device is controlled by isci driver.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
int phy_index;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* The index in Enclosure. This is what should be used when using SES-2.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
int encl_index;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
struct enclosure_device *enclosure;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* If disk is a raid member, this field will be set with a copy of raid device
|
|
Packit |
7e09eb |
* struct.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
struct raid_device *raid_dev;
|
|
Packit |
7e09eb |
};
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* @brief Creates a block device structure.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* This function allocates memory for a new structure of block device. It reads
|
|
Packit |
7e09eb |
* the sysfs entries and populates the structure fields. It performs all this
|
|
Packit |
7e09eb |
* actions only if the block device is connected to the one of supported storage
|
|
Packit |
7e09eb |
* controllers and the controller has enclosure management services enabled.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @param[in] cntrl_list pointer to a list of supported controller
|
|
Packit |
7e09eb |
* devices.
|
|
Packit |
7e09eb |
* @param[in] sysfs_path a path to block device in sysfs.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @return Pointer to block device structure if successful, otherwise the function
|
|
Packit |
7e09eb |
* returns the NULL pointer.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
struct block_device *block_device_init(const struct list *cntrl_list, const char *path);
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* @brief Releases a block device structure.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* This function releases memory allocated for block device structure.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @param[in] device pointer to block device structure.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @return The function does not return a value.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
void block_device_fini(struct block_device *device);
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* @brief Duplicates a block device structure.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* The function allocates memory for a block device structure and copies values
|
|
Packit |
7e09eb |
* stored in fields of source block structure. The function allocates new memory
|
|
Packit |
7e09eb |
* for all string fields in a copy structure. It is safe to release source block
|
|
Packit |
7e09eb |
* structure just after it has been duplicated.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @param[in] device pointer to source block device structure.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @return Pointer to block device structure if successful, otherwise the function
|
|
Packit |
7e09eb |
* returns the NULL pointer.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
struct block_device *block_device_duplicate(struct block_device *device);
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* @brief Determines a storage controller.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* This is the internal function of 'block device' module. The function gets
|
|
Packit |
7e09eb |
* a pointer to controller structure the device is connected to.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @param[in] cntrl_list pointer to list of supported controllers.
|
|
Packit |
7e09eb |
* @param[in] path path to block device in sysfs tree.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @return Pointer to controller structure if successful, otherwise the function
|
|
Packit |
7e09eb |
* returns NULL pointer. The NULL pointer means that block devices is
|
|
Packit |
7e09eb |
* connected to unsupported storage controller.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
struct cntrl_device *block_get_controller(const struct list *cntrl_list, char *path);
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* The global timestamp variable. It is updated every time the sysfs is scanning
|
|
Packit |
7e09eb |
* by an application. The value stored in this variable should be used to update
|
|
Packit |
7e09eb |
* all timestamp stored in block device structures.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
extern time_t timestamp;
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* @brief Determines if block device is attached directly or via expander
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
int dev_directly_attached(const char *path);
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* @brief Gets the host structure for given control device and host_id
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
struct _host_type *block_get_host(struct cntrl_device *cntrl, int host_id);
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
/**
|
|
Packit |
7e09eb |
* @brief Checks the presence of block device.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* This is internal function of monitor service. The function is checking
|
|
Packit |
7e09eb |
* whether block device is already on the list or it is missing from the list.
|
|
Packit |
7e09eb |
* The function is design to be used as 'test' parameter for list_find_first()
|
|
Packit |
7e09eb |
* function.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @param[in] bd_old - an element from a list to compare to.
|
|
Packit |
7e09eb |
* @param[in] bd_new - a block device being searched.
|
|
Packit |
7e09eb |
*
|
|
Packit |
7e09eb |
* @return 0 if the block devices do not match, otherwise function returns 1.
|
|
Packit |
7e09eb |
*/
|
|
Packit |
7e09eb |
int block_compare(const struct block_device *bd_old,
|
|
Packit |
7e09eb |
const struct block_device *bd_new);
|
|
Packit |
7e09eb |
|
|
Packit |
7e09eb |
#endif /* _BLOCK_H_INCLUDED_ */
|