Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA-201728: Add new function is_vlan_in_use #86

Merged
merged 1 commit into from
Jul 22, 2016

Conversation

sharady
Copy link
Collaborator

@sharady sharady commented Jul 1, 2016

Function is_vlan_in_use will identify the VLAN which is
in use by FCoE and unknown to XAPI.

Signed-off-by: sharad yadav [email protected]

error "Error: could not read %s." vlan_dir;
[]
in
if List.mem vlan vlans then true else false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's enough to say List.mem vlan vlans - the result is the boolean you are looking for

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed!! Updated that line, Thanks :)

@sharady
Copy link
Collaborator Author

sharady commented Jul 1, 2016

Lets wait for @robhoes review too, He might have some more thoughts for network backend switch ovs and linux bridge.

@robhoes
Copy link
Member

robhoes commented Jul 4, 2016

We cannot do this check based on device names. We need to use sysfs to check whether the VLAN exists in the kernel.

let vlan_device = device ^ "." ^ (Int64.to_string vlan) in
let interfaces =
try
List.map (fun interface -> List.hd (String.split '-' interface)) (Sysfs.list ())
Copy link
Member

@robhoes robhoes Jul 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still doing a lookup by device name... We should not make any assumptions about the particular device name used for the VLAN. For example, I can setup a VLAN called vlanrob on top of eth0 with tag 666. Then this function won't find it, even though the VLAN is in use.

@sharady
Copy link
Collaborator Author

sharady commented Jul 14, 2016

@robhoes I need to discuss few alternatives, will take that offline before updating PR. Thanks

@lindig
Copy link
Contributor

lindig commented Jul 19, 2016

Maybe close this PR and re-open it when you are ready?

@sharady
Copy link
Collaborator Author

sharady commented Jul 20, 2016

Lets use /proc/net/vlan/config which has details of all devices and vlan tag created. We can get rid assumption for comparing devices in sysfs.

in
(* We need only device and VLAN ID from each line of config file *)
let create_pair lst =
match (Re_str.split (Re_str.regexp_string "| ") lst) with
Copy link
Member

@robhoes robhoes Jul 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the Re_str module is not thread-safe. We've had issues with it in the past. I recommend Scanf.sscanf instead:

Scanf.sscanf lst "%s | %d | %s" (fun _ device vlan -> device, vlan)

@sharady
Copy link
Collaborator Author

sharady commented Jul 22, 2016

Thanks @robhoes for the review :) Please have a look once again.

let has_vlan _ dbg ~name ~vlan =
(* Identify the vlan is used by kernel which is unknown to XAPI *)
Debug.with_thread_associated dbg (fun () ->
List.mem ("", vlan, name) (Proc.get_vlans ())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not bother with the full_conf argument to get_vlans and always return the "full" data. You can still ignore the device name like this:

List.exists (fun (_, v, p) -> v = vlan && p = name) (Proc.get_vlans ())

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated :)

else
Scanf.sscanf lst "%s | %d | %s" (fun device vlan parent -> "", vlan, parent)
in
List.map (fun x -> create_config_list x) (List.tl (List.rev vlan_config_list))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the List.tl etc. needed here? To keep it simple, I would just try to parse all lines and ignore lines that cannot be parsed (and not even remove the first two lines). Also removing the full_conf parameter, something like:

let get_vlans () =
    try
        List.file_lines_fold (fun vlans line ->
            try
                let x = Scanf.sscanf line "%s | %d | %s" (fun device vlan parent -> device, vlan, parent)) in
                x :: vlans
            with _ ->
                vlans
        ) [] "/proc/net/vlan/config"
    with e ->
        error "Error: could not read /proc/net/vlan/config";
        []

1) Function `has_vlan` will identify the VLAN which is in use by kernel
and unknown to XAPI.
2) PIF.plug for VLAN PIF must fail with new exception `Vlan_in_use`
if VLAN is in use by kernel and unknown to XAPI.

Signed-off-by: sharad yadav <[email protected]>
@robhoes
Copy link
Member

robhoes commented Jul 22, 2016

It doesn't compile. Travis says:

File "networkd/network_server.ml", line 537, characters 14-25:
Error: This variant expression is expected to have type exn
       The constructor Vlan_in_use does not belong to type exn

However, that would be due to the xcp-idl dependency.

@robhoes
Copy link
Member

robhoes commented Jul 22, 2016

I'm going to put this in now :)

@robhoes robhoes merged commit 6cc2616 into xapi-project:master Jul 22, 2016
@sharady
Copy link
Collaborator Author

sharady commented Jul 22, 2016

Maybe because Vlan_in_use is defined in xcp-idl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants