This patch consists of the files
child_propogate.sh - Propagates the contents of the child sysfs to parentNS.
parent_share.sh - Creates a sharable volume of the sysfs for child to access.
parent_view.sh - Parent NS verifies the contents of the child sysfs.
sysfsview.c - Basic program to create namespaces for sysfs checking

Signed-off-by: Veerendra C <[EMAIL PROTECTED]>

Index: containers/netns/child_propogate.sh
===================================================================
--- /dev/null
+++ containers/netns/child_propogate.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# This script propogates the child sysfs contents to be visible for parent
+# Also it will check the parent sysfs contents are visible.
+#Propogate child sys directory
+
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-child_propogate.sh}
+TST_TOTAL=1
+TST_COUNT=1
+#set -x
+export TCID
+export TST_COUNT
+export TST_TOTAL
+
+    ret=0
+    PROPOGATE=`cat /tmp/FIFO4`
+    debug "INFO: CHILD propopagated.."
+    mount -t sysfs none /sys || ret=1
+    mkdir -p /tmp/mnt/sys || ret=1
+    mount --bind /sys /tmp/mnt/sys > /dev/null || ret=1
+    
+    if [ $ret -ne 0 ]; then
+        status=1
+        tst_resm TFAIL "error while doing bind mount"
+        exit $status
+    fi
+    #Capture childs sysfs contents
+    ls /sys/class/net > /tmp/child_sysfs
+    echo propogated > /tmp/FIFO5
+    
+    #Capture parent sysfs in child
+    ls /tmp/par_sysfs/class/net > /tmp/parent_sysfs_in_child
+    diff /tmp/parent_sysfs_in_child /tmp/parent_sysfs > /dev/null 2>&1
+    if [ $? -eq 0 ]
+    then
+        tst_resm TINFO "Pass:Child is able to view parent sysfs"
+        status=0
+    else
+        tst_resm TFAIL "Fail:Child view of sysfs is not same as parent sysfs"
+        status=1
+    fi
+
+    echo $status > /tmp/FIFO6
+    
+    #cleanup
+    rm -f /tmp/parent_sysfs_in_child /tmp/parent_sysfs 
+    umount /tmp/mnt/sys
Index: containers/netns/parent_share.sh
===================================================================
--- /dev/null
+++ containers/netns/parent_share.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+# This script is executed in the parent NS. 
+# It binds and does sharable mount of sysfs .
+#
+#For child to refer parent sys
+# set -x
+
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-parent_share.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+ret=0 
+source initialize.sh
+
+    mkdir -p /tmp/par_sysfs /tmp/mnt || ret=1
+    mount --bind /sys /tmp/par_sysfs || ret=1
+    
+    #share parent namespace
+    mount --bind /tmp/mnt /tmp/mnt || ret=1
+    #mount --make-shared /mnt
+    $smount /tmp/mnt shared > /dev/null || ret=1
+    if [ $ret -ne 0 ] ; then
+        tst_resm TFAIL "Error while doing shared mount"
+        exit -1
+    fi
Index: containers/netns/parent_view.sh
===================================================================
--- /dev/null
+++ containers/netns/parent_view.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+# This script verifies the contents of child sysfs is visible in parent NS.
+
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-parent_view.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+    
+    #capture parent /sys contents 
+    
+    debug "INFO: Parent SYSFS view" 
+    ls /sys/class/net > /tmp/parent_sysfs
+    echo PROPOGATE > /tmp/FIFO4
+    
+    PROPOGATED=`cat /tmp/FIFO5`
+    ls /tmp/mnt/sys/class/net > /tmp/child_sysfs_in_parent
+    diff /tmp/child_sysfs_in_parent /tmp/child_sysfs
+    if [ $? -eq 0 ]
+    then
+        tst_resm TINFO "Pass: Parent is able to view child sysfs"
+        status=0
+    else
+        tst_resm TFAIL "Fail: Parent is not able to view Child-NS sysfs"
+        status=-1
+    fi
+
+    stat=`cat /tmp/FIFO6`
+    if [ $stat != 0 ] ; then
+        status=$stat
+    fi
+    
+    #cleanup temp files
+    rm -f /tmp/child_sysfs_in_parent /tmp/child_sysfs 
+    umount /tmp/par_sysfs 
+    umount /tmp/mnt
+    sleep 1
+    rm -rf /tmp/par_sysfs /tmp/mnt > /dev/null 2>&1 || true
Index: containers/netns/sysfsview.c
===================================================================
--- /dev/null
+++ containers/netns/sysfsview.c
@@ -0,0 +1,70 @@
+
+/*************************************************************************
+* Copyright (c) International Business Machines Corp., 2008
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program 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 General Public License for more details.
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+***************************************************************************/
+
+/* ============================================================================
+* This testcase uses the libnetns.c from the lib to create network NS1.
+* In libnetns.c it uses 2 scripts parentns.sh and childns.sh to create this.
+*
+* This testcase verifies sysfs contents of parentNS is visible from child NS.
+* Also it checks the sysfs contents of the child are visible from the parent NS.
+* On Success it returns PASS else returns FAIL
+*
+* Scripts used: parent_share.sh parent_view.sh child_propogate.sh 
+*               parentns.sh childns.sh
+*
+* 
+* Authors:      Poornima Nayak <[EMAIL PROTECTED]>
+*               Veerendra C <[EMAIL PROTECTED]> 
+*                      31/07/2008
+* ============================================================================*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "../libclone/libclone.h"
+
+extern int create_net_namespace(char *, char *);
+int main()
+{
+    int len, ret, status = 0;
+    char *script, *ltproot;
+
+    ltproot = getenv("LTPROOT");
+    if ( ! ltproot) {
+        printf("LTPROOT env variable is not set\n");
+        printf("Please set LTPROOT and re-run the test.. Thankyou\n");
+        return -1;
+    }
+
+    len = strlen(ltproot);
+    script = malloc (len + 60);
+
+    sprintf(script, "%s/testcases/kernel/containers/netns/parent_share.sh" , ltproot);
+
+    /* Parent should be able to view child sysfs and vice versa */
+    ret = system(script);
+    status = WEXITSTATUS(ret);
+    if (status != 0) {
+        printf("Error while executing the script %s\n", script);
+        fflush(stdout);
+        exit(1);
+    }
+
+    status = create_net_namespace("parent_view.sh","child_propogate.sh");
+    return status;
+}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to