Parses the command-line arguments given by the user and takes the appropriate action for each
()
| 639 | |
| 640 | |
| 641 | def parse_args(): |
| 642 | '''Parses the command-line arguments given by the user and takes the |
| 643 | appropriate action for each''' |
| 644 | global b_flag |
| 645 | global status_flag |
| 646 | global status_dev |
| 647 | global force_flag |
| 648 | global args |
| 649 | |
| 650 | parser = argparse.ArgumentParser( |
| 651 | description='Utility to bind and unbind devices from Linux kernel', |
| 652 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 653 | epilog=""" |
| 654 | Examples: |
| 655 | --------- |
| 656 | |
| 657 | To display current device status: |
| 658 | %(prog)s --status |
| 659 | |
| 660 | To display current network device status: |
| 661 | %(prog)s --status-dev net |
| 662 | |
| 663 | To bind eth1 from the current driver and move to use vfio-pci |
| 664 | %(prog)s --bind=vfio-pci eth1 |
| 665 | |
| 666 | To unbind 0000:01:00.0 from using any driver |
| 667 | %(prog)s -u 0000:01:00.0 |
| 668 | |
| 669 | To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver |
| 670 | %(prog)s -b ixgbe 02:00.0 02:00.1 |
| 671 | """) |
| 672 | |
| 673 | parser.add_argument( |
| 674 | '-s', |
| 675 | '--status', |
| 676 | action='store_true', |
| 677 | help="Print the current status of all known devices.") |
| 678 | parser.add_argument( |
| 679 | '--status-dev', |
| 680 | help="Print the status of given device group.", |
| 681 | choices=['baseband', 'compress', 'crypto', 'dma', 'event', |
| 682 | 'mempool', 'misc', 'net', 'regex', 'ml']) |
| 683 | bind_group = parser.add_mutually_exclusive_group() |
| 684 | bind_group.add_argument( |
| 685 | '-b', |
| 686 | '--bind', |
| 687 | metavar='DRIVER', |
| 688 | help="Select the driver to use or \"none\" to unbind the device") |
| 689 | bind_group.add_argument( |
| 690 | '-u', |
| 691 | '--unbind', |
| 692 | action='store_true', |
| 693 | help="Unbind a device (equivalent to \"-b none\")") |
| 694 | parser.add_argument( |
| 695 | '--force', |
| 696 | action='store_true', |
| 697 | help=""" |
| 698 | Override restriction on binding devices in use by Linux" |