Blame src/block.h

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