mirror of
https://github.com/vishvananda/netlink
synced 2025-04-28 14:18:15 +00:00
Add an API to rename rdma device name
Add an API RdmaLinkSetName() and test case to rename a rdma device name. Signed-off-by: Parav Pandit <parav@mellanox.com>
This commit is contained in:
parent
02a383156a
commit
b48eed5d7d
@ -10,6 +10,7 @@ const (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
RDMA_NLDEV_CMD_GET = 1
|
RDMA_NLDEV_CMD_GET = 1
|
||||||
|
RDMA_NLDEV_CMD_SET = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -95,6 +95,12 @@ func execRdmaGetLink(req *nl.NetlinkRequest, name string) (*RdmaLink, error) {
|
|||||||
return nil, fmt.Errorf("Rdma device %v not found", name)
|
return nil, fmt.Errorf("Rdma device %v not found", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func execRdmaSetLink(req *nl.NetlinkRequest) error {
|
||||||
|
|
||||||
|
_, err := req.Execute(unix.NETLINK_RDMA, 0)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// RdmaLinkByName finds a link by name and returns a pointer to the object if
|
// RdmaLinkByName finds a link by name and returns a pointer to the object if
|
||||||
// found and nil error, otherwise returns error code.
|
// found and nil error, otherwise returns error code.
|
||||||
func RdmaLinkByName(name string) (*RdmaLink, error) {
|
func RdmaLinkByName(name string) (*RdmaLink, error) {
|
||||||
@ -110,3 +116,30 @@ func (h *Handle) RdmaLinkByName(name string) (*RdmaLink, error) {
|
|||||||
|
|
||||||
return execRdmaGetLink(req, name)
|
return execRdmaGetLink(req, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RdmaLinkSetName sets the name of the rdma link device. Return nil on success
|
||||||
|
// or error otherwise.
|
||||||
|
// Equivalent to: `rdma dev set $old_devname name $name`
|
||||||
|
func RdmaLinkSetName(link *RdmaLink, name string) error {
|
||||||
|
return pkgHandle.RdmaLinkSetName(link, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RdmaLinkSetName sets the name of the rdma link device. Return nil on success
|
||||||
|
// or error otherwise.
|
||||||
|
// Equivalent to: `rdma dev set $old_devname name $name`
|
||||||
|
func (h *Handle) RdmaLinkSetName(link *RdmaLink, name string) error {
|
||||||
|
proto := getProtoField(nl.RDMA_NL_NLDEV, nl.RDMA_NLDEV_CMD_SET)
|
||||||
|
req := h.newNetlinkRequest(proto, unix.NLM_F_ACK)
|
||||||
|
|
||||||
|
b := make([]byte, 4)
|
||||||
|
native.PutUint32(b, uint32(link.Attrs.Index))
|
||||||
|
data := nl.NewRtAttr(nl.RDMA_NLDEV_ATTR_DEV_INDEX, b)
|
||||||
|
req.AddData(data)
|
||||||
|
|
||||||
|
b = make([]byte, len(name)+1)
|
||||||
|
copy(b, name)
|
||||||
|
data = nl.NewRtAttr(nl.RDMA_NLDEV_ATTR_DEV_NAME, b)
|
||||||
|
req.AddData(data)
|
||||||
|
|
||||||
|
return execRdmaSetLink(req)
|
||||||
|
}
|
||||||
|
@ -32,3 +32,22 @@ func TestRdmaGetRdmaLink(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRdmaSetRdmaLinkName(t *testing.T) {
|
||||||
|
minKernelRequired(t, 4, 19)
|
||||||
|
setupRdmaKModule(t, "ib_core")
|
||||||
|
link, err := RdmaLinkByName("foo")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Set new name
|
||||||
|
err = RdmaLinkSetName(link, "bar")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Revert back to old name
|
||||||
|
err = RdmaLinkSetName(link, "foo")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user