diff options
Diffstat (limited to 'extras/devel-tools')
14 files changed, 612 insertions, 0 deletions
diff --git a/extras/devel-tools/devel-vagrant/Vagrantfile b/extras/devel-tools/devel-vagrant/Vagrantfile new file mode 100644 index 00000000000..78dc29bdc68 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/Vagrantfile @@ -0,0 +1,165 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +# +# Author: Rajesh Joseph (rjoseph@redhat.com) +# Author: Christopher Blum (cblum@redhat.com) +# + + +#Variables +box_name = "gluster-dev-fedora" +box_url = "http://download.gluster.org/pub/gluster/glusterfs/vagrant/gluster-dev-fedora/boxes/gluster-dev-fedora.json" +node_count = 0 +disk_count = -1 +node_name = "Node" +ipbase="192.168.99." +source_path = "/source/glusterfs" +target_path = "/mnt/src" + +if ARGV[0] == "up" + environment = open('vagrant_env.conf', 'w') + + print "\n\e[1;37mEnter Node (or VM) Count? Default: 1 \e[32m" + while node_count < 1 or node_count > 99 + node_count = $stdin.gets.strip.to_i + if node_count == 0 # The user pressed enter without input or we cannot parse the input to a number + node_count = 1 + elsif node_count < 1 + print "\e[31mWe need at least 1 VM ;) Try again \e[32m" + elsif node_count > 99 + print "\e[31mWe don't support more than 99 VMs - Try again \e[32m" + end + end + + print "\e[1;37mEnter per Node Disc (Brick) Count? Default: 2 \e[32m" + + while disk_count < 1 + disk_count = $stdin.gets.strip.to_i + if disk_count == 0 # The user pressed enter without input or we cannot parse the input to a number + disk_count = 2 + elsif disk_count < 1 + print "\e[31mWe need at least 1 disk ;) Try again \e[32m" + end + end + + print "\e[1;37mEnter GlusterFS source location? Default: \"#{source_path}\" : \e[32m" + tmploc = $stdin.gets.strip.to_s + if tmploc != "" + source_path = "#{tmploc}" + end + + environment.puts("# BEWARE: Do NOT modify ANY settings in here or your vagrant environment will be messed up") + environment.puts(node_count.to_s) + environment.puts(disk_count.to_s) + environment.puts(source_path) + + print "\e[32m\nOK I will provision #{node_count} VMs for you and each one will have #{disk_count} disks for bricks\e[37m\n\n" + system "sleep 1" +else # So that we destroy and can connect to all VMs... + environment = open('vagrant_env.conf', 'r') + + environment.readline # Skip the comment on top + node_count = environment.readline.to_i + disk_count = environment.readline.to_i + source_path = environment.readline.gsub(/\s+/, "") + + if ARGV[0] != "ssh-config" + puts "Detected settings from previous vagrant up:" + puts " We deployed #{node_count} VMs with each #{disk_count} disks" + puts "" + end +end + +environment.close + +$ansivar = Hash.new{ |hash,key| hash[key] = [] } +$devnamecreated = false + +# +# Function to create and attach disks +# +def attachDisks(numDisk, provider) + suffix = "bcdefghijklmn".split("") + for i in 1..numDisk.to_i + devname = "vd" + (suffix[i-1]).to_s + if $devnamecreated == false + $ansivar["device"].push "#{devname}" + end + provider.storage :file, + :size => '1G', + :device => "vd" + (suffix[i-1]).to_s, + :type => "qcow2", + :bus => "virtio", + :cache => "default" + end + $devnamecreated = true +end + + +$ansivar["src_path"].push "#{source_path}" +$ansivar["trg_path"].push "#{target_path}" + +groups = Hash.new{ |hash,key| hash[key] = [] } + +groups["origin"].push "#{node_name}1" +groups["all"].push "#{node_name}1" + +(2..node_count).each do |num| + $ansivar["peer_nodes"].push "#{node_name}#{num}" + groups["all"].push "#{node_name}#{num}" +end + +hostsFile = "\n" +(1..node_count).each do |num| + hostsFile += "#{ipbase}#{( 100 + num).to_s} #{node_name}#{num.to_s}\n" +end + +Vagrant.configure("2") do |config| + (1..node_count).each do |num| + config.vm.define "#{node_name}#{num}" do |node| + ip_addr = "#{ipbase}#{(100 + num).to_s}" + node.vm.network "private_network", ip: "#{ip_addr}" + node.vm.box = box_name + node.vm.box_url = box_url + node.vm.hostname = "#{node_name}#{num}" + node.ssh.insert_key = false + node.vm.synced_folder "#{source_path}", "#{target_path}", type: "nfs" + + # Define basic config for VM, memory, cpu, storage pool + node.vm.provider "libvirt" do |virt| + virt.storage_pool_name = "default" + virt.memory = 1024 + virt.cpus = 1 + + attachDisks( disk_count, virt ) + end + + node.vm.post_up_message = "\e[37mBuilding of this VM is finished \n" + "You can access it now with: \n" + "vagrant ssh #{node_name}#{num.to_s}\n\n" + "#{target_path} directory in VM #{node_name}#{num.to_s}" + "is synced with Host machine. \nSo any changes done in this" + "directory will be reflected in the host machine as well\n" + "Beware of this when you delete content from this directory\e[32m" + + node.vm.provision :shell, path: "bootstrap.sh" + + node.vm.provision "shell", inline: <<-SHELL + echo '#{hostsFile}' | sudo tee -a /etc/hosts + SHELL + + if num == node_count + # Let's provision + node.vm.provision "ansible" do |setup| + setup.verbose = "v" + setup.playbook = "ansible/setup.yml" + setup.limit = "all" + setup.sudo = "true" + setup.groups = groups + setup.extra_vars = $ansivar + end + end + + end + end +end diff --git a/extras/devel-tools/devel-vagrant/ansible/roles/cluster/tasks/main.yml b/extras/devel-tools/devel-vagrant/ansible/roles/cluster/tasks/main.yml new file mode 100644 index 00000000000..3306c7a3dc2 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/ansible/roles/cluster/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- name: gluster peer probe + shell: gluster peer probe {{ item }} + with_items: "{{ peer_nodes | default([]) }}" + diff --git a/extras/devel-tools/devel-vagrant/ansible/roles/compile-gluster/tasks/main.yml b/extras/devel-tools/devel-vagrant/ansible/roles/compile-gluster/tasks/main.yml new file mode 100644 index 00000000000..6ee258c7780 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/ansible/roles/compile-gluster/tasks/main.yml @@ -0,0 +1,29 @@ +--- +- name: autogen.sh + shell: chdir={{ item }} ./autogen.sh + with_items: "{{ trg_path }}" + +- name: configure + shell: chdir={{ item }} CFLAGS="-g -O0 -Werror -Wall -Wno-error=cpp -Wno-error=maybe-uninitialized" \ + ./configure \ + --prefix=/usr \ + --exec-prefix=/usr \ + --bindir=/usr/bin \ + --sbindir=/usr/sbin \ + --sysconfdir=/etc \ + --datadir=/usr/share \ + --includedir=/usr/include \ + --libdir=/usr/lib64 \ + --libexecdir=/usr/libexec \ + --localstatedir=/var \ + --sharedstatedir=/var/lib \ + --mandir=/usr/share/man \ + --infodir=/usr/share/info \ + --libdir=/usr/lib64 \ + --enable-debug + with_items: "{{ trg_path }}" + +- name: make install + shell: chdir={{ item }} make install + with_items: "{{ trg_path }}" + diff --git a/extras/devel-tools/devel-vagrant/ansible/roles/install-pkgs/tasks/main.yml b/extras/devel-tools/devel-vagrant/ansible/roles/install-pkgs/tasks/main.yml new file mode 100644 index 00000000000..3944054dd25 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/ansible/roles/install-pkgs/tasks/main.yml @@ -0,0 +1,72 @@ +--- +- name: install deltarpm + dnf: name=deltarpm state=present + +- name: update system + shell: dnf update -y + +- name: install other packages + dnf: name={{ item }} state=present + with_items: + - attr + - autoconf + - automake + - bison + - cifs-utils + - cscope + - ctags + - dbench + - dos2unix + - e2fsprogs + - findutils + - flex + - fuse-devel + - fuse-libs + - gcc + - gdb + - git + - glib2-devel + - hostname + - libacl-devel + - libaio-devel + - libattr-devel + - libibverbs-devel + - librdmacm-devel + - libtool + - libxml2-devel + - lvm2-devel + - make + - man-db + - mock + - net-tools + - nfs-utils + - openssh-server + - openssl-devel + - perl-Test-Harness + - pkgconfig + - procps-ng + - psmisc + - python-devel + - python-eventlet + - python-netifaces + - python-paste-deploy + - python-setuptools + - python-simplejson + - python-sphinx + - python-webob + - pyxattr + - readline-devel + - rpm-build + - screen + - strace + - supervisor + - systemtap-sdt-devel + - sqlite-devel + - samba* + - userspace-rcu-devel + - vim + - wget + - which + - xfsprogs + - yajl-devel + diff --git a/extras/devel-tools/devel-vagrant/ansible/roles/iptables/tasks/main.yml b/extras/devel-tools/devel-vagrant/ansible/roles/iptables/tasks/main.yml new file mode 100644 index 00000000000..768cb0e8668 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/ansible/roles/iptables/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- name: disable iptables, need to add specific rules later + shell: iptables -F diff --git a/extras/devel-tools/devel-vagrant/ansible/roles/prepare-brick/tasks/main.yml b/extras/devel-tools/devel-vagrant/ansible/roles/prepare-brick/tasks/main.yml new file mode 100644 index 00000000000..a3a6c463468 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/ansible/roles/prepare-brick/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: Create physical device + shell: pvcreate /dev/{{ item }} + with_items: "{{ device }}" + +- name: Create volume group + shell: vgcreate vg{{ item }} /dev/{{ item }} + with_items: "{{ device }}" + +- name: Create thin pool + shell: lvcreate -L 950M -T vg{{ item }}/thinpool + with_items: "{{ device }}" + +- name: Create thin volume + shell: lvcreate -V900M -T vg{{ item }}/thinpool -n thinp1 + with_items: "{{ device }}" + +- name: Format backend + filesystem: fstype=xfs dev=/dev/vg{{ item }}/thinp1 + with_items: "{{ device }}" + +- name: Create mount directory + file: path=/bricks/br{{ item }} state=directory recurse=yes + with_items: "{{ device }}" + +- name: Add entry to fstab and mount + mount: name=/bricks/br{{ item }} src=/dev/vg{{ item }}/thinp1 fstype=xfs state=mounted + with_items: "{{ device }}" + + diff --git a/extras/devel-tools/devel-vagrant/ansible/roles/selinux/tasks/main.yml b/extras/devel-tools/devel-vagrant/ansible/roles/selinux/tasks/main.yml new file mode 100644 index 00000000000..c9ba9618428 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/ansible/roles/selinux/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- name: Allow gfapi in Samba to bind to other ports than well known smb ports + seboolean: name=samba_load_libgfapi state=yes persistent=yes diff --git a/extras/devel-tools/devel-vagrant/ansible/roles/service/tasks/main.yml b/extras/devel-tools/devel-vagrant/ansible/roles/service/tasks/main.yml new file mode 100644 index 00000000000..ef78a125ae8 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/ansible/roles/service/tasks/main.yml @@ -0,0 +1,21 @@ +--- +- name: disable kernel nfs + service: name=nfs-server enabled=no + +- name: stop kernel nfs + service: name=nfs-server state=stopped + +- name: enable rpcbind + service: name=rpcbind enabled=yes + +- name: start rpcbind + service: name=rpcbind state=started + +- name: enable glusterd + service: name=glusterd enabled=yes + +- name: start glusterd + service: name=glusterd state=started + + + diff --git a/extras/devel-tools/devel-vagrant/ansible/setup.yml b/extras/devel-tools/devel-vagrant/ansible/setup.yml new file mode 100644 index 00000000000..c26bd7d6051 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/ansible/setup.yml @@ -0,0 +1,23 @@ +--- +- hosts: all + become: yes + become_method: sudo + roles: + - install-pkgs + - prepare-brick + - selinux + - iptables + +- hosts: all + become: yes + become_method: sudo + serial: 1 + roles: + - compile-gluster + - service + +- hosts: origin + become: yes + become_method: sudo + roles: + - cluster diff --git a/extras/devel-tools/devel-vagrant/bootstrap.sh b/extras/devel-tools/devel-vagrant/bootstrap.sh new file mode 100644 index 00000000000..bbf9fa2c063 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/bootstrap.sh @@ -0,0 +1,3 @@ +dnf install -y nfs-utils +dnf install -y vim +dnf install -y python2 python2-dnf libselinux-python libsemanage-python diff --git a/extras/devel-tools/devel-vagrant/up.sh b/extras/devel-tools/devel-vagrant/up.sh new file mode 100755 index 00000000000..35cbe79d835 --- /dev/null +++ b/extras/devel-tools/devel-vagrant/up.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +vagrant up --no-provision $@ +vagrant provision diff --git a/extras/devel-tools/gdb_macros b/extras/devel-tools/gdb_macros new file mode 100644 index 00000000000..aae4ccb3b37 --- /dev/null +++ b/extras/devel-tools/gdb_macros @@ -0,0 +1,84 @@ + +# +# gdb_macros is a gdb script file which can assist +# developer in debugging. This script provides +# following functions for debugging gluster processes +# effectively: +# +# pdict : This function will iterate through all the +# dictionary (dict_t) members and print the +# key-value pair. +# +# plist : This function will print address of each member +# of gluster list (list_head). +# +# gdb script should be loaded in gdb before using these +# functions. gdb script can be loaded on-demand or on gdb +# start-up. Use the following command on gdb prompt for +# loading it on-demand. +# source <script filename> +# e.g. +# (gdb) source /mnt/gdb_macros +# +# To automatically load gdb script on startup use .gdbinit +# file. This file is automatically loaded by gdb on start. +# Edit (or create) ~/.gdbinit file and add the following +# entry: +# source /mnt/gdb_macros +# + + + +# This is an internal helper function +define _print_dict_data + set $data = ($arg0) + set $len = $data->len - 1 + set $i = 0 + set $ishex = 0 + while ($i < $len) + set $ch = $data->data [$i] + + # Print only alpha-numeric values as char + # and remaining as hex value. This is done + # in this way because using %s screws up + # the display if the string has non-displayable + # characters + if ($ishex == 0) && ($ch > 31) && ($ch < 127) + printf "%c", $ch + else + printf "%x", ($ch & 0xFF) + set $ishex = 1 + end + set $i = $i + 1 + end +end + + +define pdict + set $cnt = 1 + set $temp = *($arg0->members) + while ($temp) + printf "[%d](%s::",$cnt, $temp->key + _print_dict_data ($temp)->value + printf ")\n" + set $temp = $temp->next + set $cnt = $cnt + 1 + end + printf "Done\n" +end + + +define plist + set $node = &($arg0) + set $head = $node + + printf "[0x%lx]", $node + set $node = $node->next + + while ($node != $head) + printf "--> [0x%lx]", $node + set $node = $node->next + end + printf "\n" +end + diff --git a/extras/devel-tools/print-backtrace.sh b/extras/devel-tools/print-backtrace.sh new file mode 100755 index 00000000000..33fbae288bc --- /dev/null +++ b/extras/devel-tools/print-backtrace.sh @@ -0,0 +1,115 @@ +#!/bin/bash +# sample unresolved backtrace lines picked up from a brick log that should go +# into a backtrace file eg. bt-file.txt: +# /usr/lib64/glusterfs/3.8.4/xlator/cluster/replicate.so(+0x3ec81)[0x7fe4bc271c81] +# /usr/lib64/glusterfs/3.8.4/xlator/cluster/replicate.so(+0x3eecd)[0x7fe4bc271ecd] +# /usr/lib64/glusterfs/3.8.4/xlator/cluster/replicate.so(+0x404cb)[0x7fe4bc2734cb] +# /usr/lib64/glusterfs/3.8.4/xlator/cluster/replicate.so(+0x3d2b6)[0x7fe4bc2702b6] +# /usr/lib64/glusterfs/3.8.4/xlator/cluster/replicate.so(+0x3d323)[0x7fe4bc270323] +# +# following is the output of the script for the above backtrace lines: +# /usr/lib64/glusterfs/3.8.4/xlator/cluster/replicate.so(+0x3ec81)[0x7fe4bc271c81] __afr_selfheal_data_finalize_source inlined at /usr/src/debug/glusterfs-3.8.4/xlators/cluster/afr/src/afr-self-heal-data.c:684 in __afr_selfheal_data_prepare /usr/src/debug/glusterfs-3.8.4/xlators/cluster/afr/src/afr-self-heal-data.c:603 +# /usr/lib64/glusterfs/3.8.4/xlator/cluster/replicate.so(+0x3eecd)[0x7fe4bc271ecd] __afr_selfheal_data /usr/src/debug/glusterfs-3.8.4/xlators/cluster/afr/src/afr-self-heal-data.c:740 +# /usr/lib64/glusterfs/3.8.4/xlator/cluster/replicate.so(+0x404cb)[0x7fe4bc2734cb] afr_selfheal_data /usr/src/debug/glusterfs-3.8.4/xlators/cluster/afr/src/afr-self-heal-data.c:883 +# /usr/lib64/glusterfs/3.8.4/xlator/cluster/replicate.so(+0x3d2b6)[0x7fe4bc2702b6] afr_selfheal_do /usr/src/debug/glusterfs-3.8.4/xlators/cluster/afr/src/afr-self-heal-common.c:1968 +# /usr/lib64/glusterfs/3.8.4/xlator/cluster/replicate.so(+0x3d323)[0x7fe4bc270323] afr_selfheal /usr/src/debug/glusterfs-3.8.4/xlators/cluster/afr/src/afr-self-heal-common.c:2015 +# +# Usage with debuginfo RPM: +# print-backtrace.sh $HOME/Downloads/glusterfs-debuginfo-3.8.4-10.el7.x86_64.rpm bt-file.txt +# +# Usage with source install: +# print-packtrace.sh none bt-file.txt + +function version_compare() { test $(echo $1|awk -F '.' '{print $1 $2 $3}') -gt $(echo $2|awk -F '.' '{print $1 $2 $3}'); } + +function Usage() +{ + echo -e "Usage:\n\t$0 { none | <debuginfo-rpm> } <backtrace-file>" + echo "none: implies we don't have a debuginfo rpm but want to resolve" + echo " against a source install which already has the debuginfo" + echo " NOTE: in this case you should have configured the build" + echo " with --enable-debug and the linker options should" + echo " have the option -rdynamic" +} + +debuginfo_rpm=$1 +backtrace_file=$2 + +if [ ! $debuginfo_rpm ] || [ ! $backtrace_file ]; then + Usage + exit 1 +fi + +if [ $debuginfo_rpm != "none" ]; then + if [ ! -f $debuginfo_rpm ]; then + echo "no such rpm file: $debuginfo_rpm" + exit 1 + fi +fi + +if [ ! -f $backtrace_file ]; then + echo "no such backtrace file: $backtrace_file" + exit 1 +fi + +if [ "$debuginfo_rpm" != "none" ]; then + if ! file $debuginfo_rpm | grep RPM >/dev/null 2>&1 ; then + echo "file does not look like an rpm: $debuginfo_rpm" + exit 1 + fi +fi + +cpio_version=$(cpio --version|grep cpio|cut -f 2 -d ')'|sed -e 's/^[[:space:]]*//') +rpm_name="" +debuginfo_path="" +debuginfo_extension="" + +if [ $debuginfo_rpm != "none" ]; then + # extract the gluster debuginfo rpm to resolve the symbols against + rpm_name=$(basename $debuginfo_rpm '.rpm') + if [ -d $rpm_name ]; then + echo "directory already exists: $rpm_name" + echo "please remove/move it and reattempt" + exit 1 + fi + mkdir -p $rpm_name + if version_compare $cpio_version "2.11"; then + rpm2cpio $debuginfo_rpm | cpio --quiet --extract --make-directories --preserve-modification-time --directory=$rpm_name + ret=$? + else + current_dir="$PWD" + cd $rpm_name + rpm2cpio $debuginfo_rpm | cpio --quiet --extract --make-directories --preserve-modification-time + ret=$? + cd $current_dir + fi + if [ $ret -eq 1 ]; then + echo "failed to extract rpm $debuginfo_rpm to $PWD/$rpm_name directory" + rm -rf $rpm_name + exit 1 + fi + debuginfo_path="$PWD/$rpm_name/usr/lib/debug" + debuginfo_extension=".debug" +else + debuginfo_path="" + debuginfo_extension="" +fi + +# NOTE: backtrace file should contain only the lines which need to be resolved +for bt in $(cat $backtrace_file) +do + libname=$(echo $bt | cut -f 1 -d '(') + addr=$(echo $bt | cut -f 2 -d '(' | cut -f 1 -d ')') + libpath=${debuginfo_path}${libname}${debuginfo_extension} + if [ ! -f $libpath ]; then + continue + fi + newbt=( $(eu-addr2line --functions --exe=$libpath $addr) ) + echo "$bt ${newbt[*]}" +done + +# remove the temporary directory +if [ -d $rpm_name ]; then + rm -rf $rpm_name +fi + diff --git a/extras/devel-tools/strace-brick.sh b/extras/devel-tools/strace-brick.sh new file mode 100755 index 00000000000..a140729111c --- /dev/null +++ b/extras/devel-tools/strace-brick.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# Usage: +# nice -n -19 strace-brick.sh glusterfsd 50 + +brick_process_name=$1 +min_watch_cpu=$2 +if [ ! $brick_process_name ]; then + brick_process_name=glusterfsd +fi + +if [ ! $min_watch_cpu ]; then + min_watch_cpu=50 +fi + +echo "min_watch_cpu: $min_watch_cpu" + +break=false + +while ! $break; +do + mypids=( $(pgrep $brick_process_name) ) + echo "mypids: ${mypids[*]}" + + pid_args=$(echo ${mypids[*]} | sed -e 's/ / -p /g;s/^/-p /') + echo "pid_args: $pid_args" + + pcpu=( $(ps $pid_args -o pcpu -h ) ) + echo "pcpu: ${pcpu[*]}" + + wait_longer=false + + for i in $( seq 0 $((${#pcpu[*]} - 1)) ) + do + echo "i: $i" + echo "mypids[$i]: ${mypids[$i]}" + + int_pcpu=$(echo ${pcpu[$i]} | cut -f 1 -d '.') + echo "int_pcpu: $int_pcpu" + if [ ! $int_pcpu ] || [ ! $min_watch_cpu ]; then + break=true + echo "breaking" + fi + if [ $int_pcpu -ge $min_watch_cpu ]; then + wait_longer=true + mydirname="${brick_process_name}-${mypids[$i]}-$(date --utc +'%Y%m%d-%H%M%S.%N')" + $(mkdir $mydirname && cd $mydirname && timeout --kill-after=5 --signal=KILL 60 nice -n -19 strace -p ${mypids[$i]} -ff -tt -T -o $brick_process_name) & + fi + done + + if $wait_longer; then + sleep 90 + else + sleep 15 + fi +done |
