Commit 7e552151 authored by Zhu Yong's avatar Zhu Yong
Browse files

add comments for exported methods

parent 94b19d29
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
@@ -5,7 +5,9 @@ import (
)

// BlockConnection is block version of connection to kinetic drvice.
// For all API fucntions, it will only return after get response from kinetic drvice.
// For all API fucntions, it will only return after response from kinetic device handled.
// If no data required from kinetic device, API function will return Status and error.
// If any data required from kinetic device, the data will be one of the return values.
type BlockConnection struct {
	nbc *NonBlockConnection
}
@@ -91,6 +93,8 @@ func (conn *BlockConnection) GetKeyRange(r *KeyRange) ([][]byte, Status, error)
	return callback.Keys, callback.Status(), err
}

// GetVersion gets object DB version information.
// On success, version information will return and Status.Code = OK
func (conn *BlockConnection) GetVersion(key []byte) ([]byte, Status, error) {
	callback := &GetVersionCallback{}
	h := NewResponseHandler(callback)
@@ -104,6 +108,8 @@ func (conn *BlockConnection) GetVersion(key []byte) ([]byte, Status, error) {
	return callback.Version, callback.Status(), err
}

// Flush requests kinetic device to write all cached data to persistent media.
// On success, Status.Code = OK
func (conn *BlockConnection) Flush() (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
@@ -117,6 +123,8 @@ func (conn *BlockConnection) Flush() (Status, error) {
	return callback.Status(), err
}

// Delete deletes object from kinetic device.
// On success, Status.Code = OK
func (conn *BlockConnection) Delete(entry *Record) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
@@ -130,6 +138,8 @@ func (conn *BlockConnection) Delete(entry *Record) (Status, error) {
	return callback.Status(), err
}

// Put store object to kinetic device.
// On success, Status.Code = OK
func (conn *BlockConnection) Put(entry *Record) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
@@ -156,6 +166,8 @@ func (conn *BlockConnection) P2PPush(request *P2PPushRequest) ([]Status, Status,
	return callback.Statuses, callback.Status(), err
}

// GetLog gets kinetic device Log information. Can request single LogType or multiple LogType.
// On success, device Log information will return, and Status.Code = OK
func (conn *BlockConnection) GetLog(logs []LogType) (*Log, Status, error) {
	callback := &GetLogCallback{}
	h := NewResponseHandler(callback)
@@ -193,23 +205,38 @@ func (conn *BlockConnection) pinop(pin []byte, op kproto.Command_PinOperation_Pi
	return callback.Status(), err
}

// SecureErase request kinetic device to perform secure erase.
// SSL connection is requested to perform this operation, and the erase pin is needed.
// On success, Status.Code = OK
func (conn *BlockConnection) SecureErase(pin []byte) (Status, error) {
	return conn.pinop(pin, kproto.Command_PinOperation_SECURE_ERASE_PINOP)
}

// InstantErase request kinetic device to perform instant erase.
// SSL connection is requested to perform this operation, and the erase pin is needed.
// On success, Status.Code = OK
func (conn *BlockConnection) InstantErase(pin []byte) (Status, error) {
	return conn.pinop(pin, kproto.Command_PinOperation_ERASE_PINOP)

}

// LockDevice locks the kinetic device.
// SSL connection is requested to perform this operation, and the lock pin is needed.
// On success, Status.Code = OK
func (conn *BlockConnection) LockDevice(pin []byte) (Status, error) {
	return conn.pinop(pin, kproto.Command_PinOperation_LOCK_PINOP)
}

// UnlockDevice unlocks the kinetic device.
// SSL connection is requested to perform this operation, and the lock pin is needed.
// On success, Status.Code = OK
func (conn *BlockConnection) UnlockDevice(pin []byte) (Status, error) {
	return conn.pinop(pin, kproto.Command_PinOperation_UNLOCK_PINOP)
}

// UpdateFirmware requests to update kientic device firmware.
// Status.OK will return if firmware data received by kinetic device.
// Then drive will reboot and perform the firmware update process.
func (conn *BlockConnection) UpdateFirmware(code []byte) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
@@ -223,6 +250,8 @@ func (conn *BlockConnection) UpdateFirmware(code []byte) (Status, error) {
	return callback.Status(), err
}

// SetClusterVersion sets the cluster version on kinetic drive.
// On success, Status.Code = OK.
func (conn *BlockConnection) SetClusterVersion(version int64) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
@@ -236,10 +265,14 @@ func (conn *BlockConnection) SetClusterVersion(version int64) (Status, error) {
	return callback.Status(), err
}

// SetClientClusterVersion sets the cluster version for all following message to kinetic device.
func (conn *BlockConnection) SetClientClusterVersion(version int64) {
	conn.nbc.SetClientClusterVersion(version)
}

// SetLockPin changes kinetic device lock pin. Both current pin and new pin needed.
// SSL connection is required to perform this operation.
// On success, Status.Code = OK.
func (conn *BlockConnection) SetLockPin(currentPin []byte, newPin []byte) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
@@ -253,6 +286,9 @@ func (conn *BlockConnection) SetLockPin(currentPin []byte, newPin []byte) (Statu
	return callback.Status(), err
}

// SetErasePin changes kinetic device erase pin. Both current pin and new pin needed.
// SSL connection is required to perform this operation.
// On success, Status.Code = OK.
func (conn *BlockConnection) SetErasePin(currentPin []byte, newPin []byte) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
@@ -266,6 +302,8 @@ func (conn *BlockConnection) SetErasePin(currentPin []byte, newPin []byte) (Stat
	return callback.Status(), err
}

// SetACL sets Permission for particular user Identify.
// On success, Status.Code = OK.
func (conn *BlockConnection) SetACL(acls []SecurityACL) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
@@ -279,6 +317,7 @@ func (conn *BlockConnection) SetACL(acls []SecurityACL) (Status, error) {
	return callback.Status(), err
}

// MediaScan
func (conn *BlockConnection) MediaScan(op *MediaOperation, pri Priority) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
@@ -292,6 +331,7 @@ func (conn *BlockConnection) MediaScan(op *MediaOperation, pri Priority) (Status
	return callback.Status(), err
}

// MediaOptimize
func (conn *BlockConnection) MediaOptimize(op *MediaOperation, pri Priority) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
@@ -305,6 +345,7 @@ func (conn *BlockConnection) MediaOptimize(op *MediaOperation, pri Priority) (St
	return callback.Status(), err
}

// Close the connection to kientic device
func (conn *BlockConnection) Close() {
	conn.nbc.Close()
}
+8 −2
Original line number Diff line number Diff line
@@ -83,25 +83,28 @@ func convertLogTypeFromProto(l kproto.Command_GetLog_Type) LogType {
	return ret
}

// UtilizationLog for kinetic drive utilization information
// UtilizationLog for kinetic device utilization information.
type UtilizationLog struct {
	Name  string  // Name of the device utlity
	Value float32 // Value of device utility
}

// TemperatureLog for kinetic device tempture.
type TemperatureLog struct {
	Name    string  // Name of the drive
	Name    string  // Name of the device
	Current float32 // Current Temperature
	Minimum float32 // Minimum Temperature for drive
	Maximum float32 // Maximum Tempture for drive
	Target  float32 // Target Temperature for drive
}

// CapacityLog for kinetic device capacity information.
type CapacityLog struct {
	CapacityInBytes uint64  // total capacity of hard disk, in bytes
	PortionFull     float32 // remaining capacity of hard disk
}

// ConfigurationInterface for kinetic device network interfaces information.
type ConfigurationInterface struct {
	Name     string // network device name
	MAC      []byte // network device mac address
@@ -109,6 +112,7 @@ type ConfigurationInterface struct {
	Ipv6Addr []byte // network device ipv6 address
}

// ConfigurationLog for kinetic device configuration information.
type ConfigurationLog struct {
	Vendor                  string                   // Vendor name
	Model                   string                   // Device model
@@ -137,6 +141,7 @@ type StatisticsLog struct {
	Bytes uint64
}

// LimitsLog defines max values.
type LimitsLog struct {
	MaxKeySize                  uint32 // max key size
	MaxValueSize                uint32 // max value size
@@ -157,6 +162,7 @@ type DeviceLog struct {
	Name []byte
}

// Log is the top level structure that groups all the log information
type Log struct {
	Utilizations  []UtilizationLog  // List of utilization information of the drive
	Temperatures  []TemperatureLog  // List of tempeture inforamtion of the drive
+3 −3
Original line number Diff line number Diff line
@@ -385,9 +385,9 @@ func convertAlgoFromProto(a kproto.Command_Algorithm) Algorithm {
// Synchronization allows the puts and deletes to determine if they are to be
// SYNC_WRITETHROUGH: This request is made persistent before returning. This does not effect any other pending operations.
// SYNC_WRITEBACK: They can be made persistent when the device chooses, or when a subsequent FLUSH is give to the device.
// SYNC_FLUSH: All pending information that has not been written is pushed to the disk and the command that
//    specifies FLUSH is written last and then returned. All WRITEBACK writes that have received ending
//    status will be guaranteed to be written before the FLUSH operation is returned completed.
// SYNC_FLUSH: All pending information that has not been written is pushed to the disk and the command that specifies
// FLUSH is written last and then returned. All WRITEBACK writes that have received ending status will be guaranteed
// to be written before the FLUSH operation is returned completed.
type Synchronization int32

const (
+1 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ type Status struct {
	ExpectedClusterVersion int64
}

// Error returns the detail status message if Status.Code != OK
func (s Status) Error() string {
	return s.ErrorMsg
}
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ func UpdateFirmware(conn *BlockConnection, file string) error {
// and prefix is the key prefix. The applet file may stored into multiple object files
// on drive depends on its size.
// Upon succeed, objects' keys are returned, output key pattern is "prefix-DDDDDDDDDD",
// where DDDDDDDDDD is the starting byte offset from the orginal file.
// where DDDDDDDDDD is 10 digits byte offset from starting of the orginal file.
func UploadAppletFile(conn *BlockConnection, file, prefix string) ([][]byte, error) {
	info, err := os.Stat(file)
	if err != nil {
Loading