libvirt/examples/lxcconvert/virt-lxc-convert
Daniel P. Berrangé 600462834f Remove all Author(s): lines from source file headers
In many files there are header comments that contain an Author:
statement, supposedly reflecting who originally wrote the code.
In a large collaborative project like libvirt, any non-trivial
file will have been modified by a large number of different
contributors. IOW, the Author: comments are quickly out of date,
omitting people who have made significant contribitions.

In some places Author: lines have been added despite the person
merely being responsible for creating the file by moving existing
code out of another file. IOW, the Author: lines give an incorrect
record of authorship.

With this all in mind, the comments are useless as a means to identify
who to talk to about code in a particular file. Contributors will always
be better off using 'git log' and 'git blame' if they need to  find the
author of a particular bit of code.

This commit thus deletes all Author: comments from the source and adds
a rule to prevent them reappearing.

The Copyright headers are similarly misleading and inaccurate, however,
we cannot delete these as they have legal meaning, despite being largely
inaccurate. In addition only the copyright holder is permitted to change
their respective copyright statement.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-12-13 16:08:38 +00:00

127 lines
3.4 KiB
Bash

#!/bin/sh
# lxc_native.c: LXC native configuration import
#
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see
# <http://www.gnu.org/licenses/>.
#
handler_cleanup()
{
if test "$conf_dir"; then
# Remove the temporary config
rm -r "$conf_dir"
fi
}
trap handler_cleanup INT EXIT
show_help()
{
cat << EOF
$0 /path/to/lxc/config/file
Wrapper around virsh domxml-from-native to ease conversion of LXC
containers configuration to libvirt domain XML.
EOF
}
if test $# != 1; then
show_help
exit 1
fi
if test "$1" = "--help" || test "$1" = "-h"; then
show_help
exit $?
fi
conf=$1
conf_dir=$(mktemp --tmpdir -d virt-lxc-convert-XXX)
conf_new=$conf_dir/config
cp "$conf" "$conf_new"
# Do we have lxc.mount, and is it pointing to a readable file?
fstab=$(sed -n '/lxc.mount[[:space:]]*=/ s/[[:space:]]*=[[:space:]]*/=/p' \
"$conf_new" | cut -f 2 -d '=')
if test -r "$fstab"; then
sed 's/^lxc.mount[[:space:]]*=.*$//' "$conf_new" >"${conf_new}.tmp"
mv "${conf_new}.tmp" "${conf_new}"
sed 's/^\([^#]\)/lxc.mount.entry = \1/' "$fstab" >>"${conf_new}"
fi
memory=$(free -b | sed -n '/Mem:/s/ \+/ /gp' | cut -f 2 -d ' ')
default_tmpfs="size=$((memory/2))"
# Do we have tmpfs without size param?
lineno=0
while read line; do
lineno=$(expr $lineno + 1)
has_rel_size=false
case $line in
lxc.mount.entry[[:space:]]*=[[:space:]]*tmpfs[[:space:]]*)
is_tmpfs=true
;;
*)
is_tmpfs=false
;;
esac
# We only care about tmpfs mount entries here
if ! $is_tmpfs; then
continue
fi
case $line in
*size=[0-9][0-9]*%*)
has_rel_size=true
has_size=true
;;
*size=*)
has_size=true
;;
*)
has_size=false
;;
esac
# Add the default size here (50%) if no size is given
if ! $has_size; then
last_option_match="\([[:space:]]*[0-9][[:space:]]*[0-9][::space::]*$\)"
sed "${lineno}s/$last_option_match/,$default_tmpfs\1/" \
"$conf_new" >"${conf_new}.tmp"
mv "${conf_new}.tmp" "${conf_new}"
fi
# Convert relative sizes
if $has_rel_size; then
percent=$(echo "$line" | sed 's/.*size=\([0-9][0-9]*\)%.*/\1/')
size="$((memory*percent/100))"
sed "${lineno}s/size=[0-9]*%/size=${size}/" \
"$conf_new" >"${conf_new}.tmp"
mv "${conf_new}.tmp" "${conf_new}"
fi
done < "$conf_new"
# Do we have any memory limit set?
mem_limit=$(grep 'lxc.cgroup.memory.limit_in_bytes[[:space:]]*=' $conf_new)
if test -z "$mem_limit"; then
echo "lxc.cgroup.memory.limit_in_bytes = $memory" >> "$conf_new"
fi
virsh -c lxc:///system domxml-from-native lxc-tools $conf_new
exit $?