Whamcloud - gitweb
LU-13004 ptlrpc: Allow BULK_BUF_KIOV to accept a kvec
[fs/lustre-release.git] / lustre / scripts / lustre_routes_conversion
1 #!/bin/bash
2 #
3 # lustre_routes_conversion
4 #   This script takes a file with routes configured as follows:
5 # <network>  [<hop>] <gateway>@<exit network>[:<priority>];
6 # Ex:
7 # tcp1 10.1.1.2@tcp0:1
8 # or
9 # tcp1 1 10.1.1.2@tcp0
10 #
11 # and converts it to:
12 # <network>: { gateway: <gateway>@<exit network> [hop: <hop>] [priority:
13 #              <priority>] }
14 #
15 # The purpose of this script is to covert legacy route configuration
16 # syntax to the new route configuration syntax
17 #
18 ############################################################################
19
20 progname=$(basename $0)
21
22 usage() {
23         cat <<- USAGE
24         convert legacy route config syntax to new route config syntax"
25         usage: $progname <legacy file> <new file>
26             -h|--help: display this message
27         USAGE
28 }
29
30 while [ ! -f "$1" ]; do
31         case "$1" in
32         -h|--help)    usage; exit 0 ;;
33         *)            usage; exit 1 ;;
34         esac
35 done
36
37 [ -z "$1" ] || [ -z "$2" ] && usage && exit 1
38
39 # Usage: read_and_parse <file name>
40 # Read a routes_config file and parse it out, then feed the proper input
41 # int lcl --net <> add_route <> to configure a route.
42 read_and_parse()
43 {
44         local infile=$1
45         local outfile=$2
46
47         while read line; do
48                 # Split the input string at ';', since multiple routes on
49                 # the same line are separated by ';'
50                 OLDIFS="$IFS"
51                 IFS=';'
52
53                 # It is possible that one single line can contain multiple
54                 # route entries.
55                 multi_routes=($line)
56                 echo "${multi_routes[@]}"
57
58                 # Iterate over each of the routes on this line.  This
59                 # returns indicies from the routes[] array, which are
60                 # dereferenced and split separately to avoid confusion
61                 # between whitespaces of routes on the same line.
62                 for index in "${!multi_routes[@]}"; do
63                         # initialize variables.
64                         local network=""
65                         local gateway=""
66                         local gatewayorhop=""
67                         local priority=""
68                         local hop=""
69
70                         # Split at ':' and '  ' to get the priority if it exists
71                         # Also will split all the different tokens in the
72                         # line.
73                         IFS="$OLDIFS: "
74                         tokens=(${multi_routes[$index]})
75
76                         # Split at ' ' to separate the network from the gateway
77                         network=${tokens[0]}
78                         gatewayorhop=${tokens[1]}
79
80                         # since hop is an optional parameter after we get this
81                         # position we need to check if we got the hop or gateway
82                         # parameter.  Set gateway is always of the form ip@intf,
83                         # then we can simply check for the '@' character in the
84                         # string.  if it exists then we don't have a hop but a
85                         # gateway.  If we don't then we assume that a hop exists
86                         # and a gateway follows it
87                         if [[ "$gatewayorhop" == *@* ]]; then
88                                 gateway=$gatewayorhop
89                                 priority=${tokens[2]}
90                         else
91                                 hop=$gatewayorhop
92                                 gateway=${tokens[2]}
93                                 priority=${tokens[3]}
94                         fi
95
96                         if [ -z "$network" ] || [ -z "$gateway" ]; then
97                                 continue;
98                         fi
99
100                         # Write the translated line into the file.
101                         echo -n "$network: { gateway: $gateway"
102                         [ -n "$hop" ] && echo -n ", hop: $hop"
103                         [ -n "$priority" ] && echo -n ", priority: $priority"
104                         echo " }"
105                 done >> "$outfile"
106         done < "$infile"
107         echo "$progname: converted routes written to $outfile"
108 }
109
110 read_and_parse $1 $2