Search This Blog

Tuesday, December 17, 2013

Shared Storage with OCFS2

Hi Friends,
How is it going ? Well today i am here to share with you how to share your shared storage (SAN in shared mode or shared iscsi lun ) across multiple nodes. Here we go

Do these steps on all nodes you wish to have shared storage

Step 1: Install ocfs2 tools on each of the nodes. Lets me assume you have debian based distro. Use relative commands for other distro

# apt-get install ocfs2-tools ocfs2console

Step 2: Edit default configuration file and enable O2CB

# vi /etc/default/o2cb

change

O2CB_ENABLED = false

to

O2CB_ENABLED = true

Step 3: Create the clustering configuration

# vi /etc/ocfs2/cluster.conf

Add these contents

node:
        ip_port = 7777
        ip_address = <node 1 ip>
        number = 1
        name = <node 1 host name>
        cluster = ocfs2
node:
        ip_port = 7777
        ip_address = <node 2 ip>
        number = 2
        name = <node 2 host name>
        cluster = ocfs2
cluster:
        node_count = 2
        name = ocfs2

Here
        <node # ip> is the node ip
        <node # host name> is the host name of node

I have assumed that my cluster consists of 2 nodes. If there are more nodes add more node parameter group and change node_count = <total of nodes in the cluster>

Step 4: start or restart o2cb service

# /etc/init.d/o2cb restart

Step 5: Change vm.dirty_ratio to reduce caching of files as it would create some lag in shared cluster.

# vi /etc/sysctl.conf

Add this line to the end of file, if it does not exists anywhere in the file

vm.dirty_ratio=10

Save the file and exit

Step 6: This step is performed on only one of the nodes. Here we format the file system to ocfs2 format

# mkfs.ocfs2 -b 4k -C 32k -L <any cluster name> -N <max no. of nodes> /dev/<shared device path>

example

# mkfs.ocfs2 -b 4k -C 32k  -L "cluster-storage" -N2 /dev/sdb1

Step 7: Perform the following steps on all nodes

# modprobe ocfs2_stackglue

Mount the shared partition on all nodes

# mount /dev/<shared device path> <mount point>

example

# mount /dev/sdb1 /mnt/

Step 8: Testing the shared storage

# touch <mounted location>/a

list it across all the other nodes

# ls <mounted location>

You must be able to see the shared data on all nodes :)

Sunday, December 15, 2013

Solution to Problem installing BCM Wireless drivers in linux

Hi All,
This is another page i write today which might help few people like me who struggled installing bcm wireless drivers on linux (debian). It may work for other flavors too. So steps are as follows.

Get to the terminal as root user and typw,

# lspci

and if you find something like this on the output of the command

Network controller: Broadcom Corporation BCM4313 802.11b/g/n Wireless LAN Controller (rev 01)

Then this solution might help you.

Download the bcm drivers from (choose your architecture)

http://www.broadcom.com/support/802.11/linux_sta.php

Also download the patch from the following site


Get to the folder where you downloaded the drivers

# cd <download driver>

Extract the driver and apply the patch

# tar zxvf <downloaded file name>
# cd <extracted folder>
# mv <patch> .
# patch -p0 src/wl/sys/wl_linux.c < bc_wl_abiupdate.patch

Compile the drivers

# make
# make install

Insert the module

# insmod /lib/modules/`uname -r`/wl.ko
# modprobe wl

There you go

Your wireless drivers are up. Tadaaaaaaaaaaa 

Thursday, June 27, 2013

Mounting VHD Image file in Linux

Back again,

So i have been playing around with so called VHD based image for a while. Here came the requirement, where i needed to mount this image and push in some keys... This is the solution i found

Step 1: Install the virtualbox fuse package which is required to open up this vhd image into its raw form

# apt-get install virtualbox-fuse

Step 2: Open up VHD image

# vdfuse -w -f <path to vhd image> <path to mount point>

Step 3: Check the extracted Files

# ls <path to mount point>

Here it could list either 

# EntireDisk

Lets mark this CASE 1

     (or)

# EntireDisk Partition1 Partion2 . ...

Depending on the number of partitions made on the Disk while creating and lets mark this as CASE 2

Step 4: Mount the extracted RAW image

# mount <path to vhd image>/EntireDisk <path to one more new mount point path>

In case of CASE 1

     (or)

# mount <path to vhd image>/Partition1 <path to one more new mount point>

In case of CASE 2
Partition here could be the one you wanted to mount

Step 5: unmounting the IMG and VHD after usage

# umount <path to mounted IMG partition>

# umount <path to vhd image>

Hope this is useful for all of you who see this :)

Tuesday, April 9, 2013

XCP hidden console

Hi all,

    Today am gonna introduce a hidden command on XCP's "xe tool stack"
Most of you who are familiar with xen's, xm console command, might wonder why such a command is missing in xe toolstack.

For those of you who wonder,
yes, xe tool-stack does have such a command, but it is hidden from help option.

So, you can access your VM, if you know its uuid

# xe console uuid=<uuid of VM>

Wednesday, January 30, 2013

Interesting problems from Facebook hackers cup

Hi friends,
Yesterday i participated on a coding contest.. Felt it is worth sharing :)
Hope you enjoy it too...........

BEAUTIFUL STRINGS

When John was a little kid he didn't have much to do. There was no internet, no Facebook, and no programs to hack on. So he did the only thing he could... he evaluated the beauty of strings in a quest to discover the most beautiful string in the world.

Given a string s, little Johnny defined the beauty of the string as the sum of the beauty of the letters in it.

The beauty of each letter is an integer between 1 and 26, inclusive, and no two letters have the same beauty. Johnny doesn't care about whether letters are uppercase or lowercase, so that doesn't affect the beauty of a letter. (Uppercase 'F' is exactly as beautiful as lowercase 'f', for example.)

You're a student writing a report on the youth of this famous hacker. You found the string that Johnny considered most beautiful. What is the maximum possible beauty of this string?

Input
The input file consists of a single integer m followed by m lines.

Output
Your output should consist of, for each test case, a line containing the string "Case #x: y" where x is the case number (with 1 being the first case in the input file, 2 being the second, etc.) and y is the maximum beauty for that test case.


Constraints
5 ≤ m ≤ 50
2 ≤ length of s ≤ 500

Example input

5
ABbCcc
Good luck in the Facebook Hacker Cup this year!
Ignore punctuation, please :)
Sometimes test cases are hard to make up.
So I just go consult Professor Dalves

Example output

Case #1: 152
Case #2: 754
Case #3: 491
Case #4: 729
Case #5: 646


*********************************************************************************


BALANCED SMILEYS


Your friend John uses a lot of emoticons when you talk to him on Messenger. In addition to being a person who likes to express himself through emoticons, he hates unbalanced parenthesis so much that it makes him go :(

Sometimes he puts emoticons within parentheses, and you find it hard to tell if a parenthesis really is a parenthesis or part of an emoticon.

A message has balanced parentheses if it consists of one of the following:
- An empty string ""
- One or more of the following characters: 'a' to 'z', ' ' (a space) or ':' (a colon)
- An open parenthesis '(', followed by a message with balanced parentheses, followed by a close parenthesis ')'.
- A message with balanced parentheses followed by another message with balanced parentheses.
- A smiley face ":)" or a frowny face ":("

Write a program that determines if there is a way to interpret his message while leaving the parentheses balanced.

Input
The first line of the input contains a number T (1 ≤ T ≤ 50), the number of test cases. The following T lines each contain a message of length s that you got from John.

Output
For each of the test cases numbered in order from 1 to T, output "Case #i: " followed by a string stating whether or not it is possible that the message had balanced parentheses. If it is, the string should be "YES", else it should be "NO" (all quotes for clarity only)

Constraints
1 ≤ length of s ≤ 100

Example input

5
:((
i am sick today (:()
(:)
hacker cup: started :):)
)(

Example output
Case #1: NO
Case #2: YES
Case #3: YES
Case #4: YES
Case #5: NO


*********************************************************************************

FIND MIN


After sending smileys, John decided to play with arrays. Did you know that hackers enjoy playing with arrays? John has a zero-based index array, m, which contains n non-negative integers. However, only the first k values of the array are known to him, and he wants to figure out the rest.

John knows the following: for each index i, where k <= i < n, m[i] is the minimum non-negative integer which is *not* contained in the previous *k* values of m.

For example, if k = 3, n = 4 and the known values of m are [2, 3, 0], he can figure out that m[3] = 1.

John is very busy making the world more open and connected, as such, he doesn't have time to figure out the rest of the array. It is your task to help him.

Given the first k values of m, calculate the nth value of this array. (i.e. m[n - 1]).

Because the values of n and k can be very large, we use a pseudo-random number generator to calculate the first k values of m. Given non-negative integers a, b, c and positive integer r, the known values of m can be calculated as follows:
m[0] = a
m[i] = (b * m[i - 1] + c) % r, 0 < i < k

Input
The first line contains an integer T (T <= 20), the number of test cases. This is followed by T test cases, consisting of 2 lines each. The first line of each test case contains 2 space separated integers, n, k (1 <= k <= 105, k < n <= 109). The second line of each test case contains 4 space separated integers a, b, c, r (0 <= a, b, c <= 109, 1 <= r <= 109).

Output
For each test case, output a single line containing the case number and the nth element of m.

Example input

5
97 39
34 37 656 97
186 75
68 16 539 186
137 49
48 17 461 137
98 59
6 30 524 98
46 18
7 11 9 46

Example output

Case #1: 8
Case #2: 38
Case #3: 41
Case #4: 40
Case #5: 12

Saturday, January 26, 2013

Freeing your RAM

Hi friends,
I was working on a server and suddenly the machine seemed to kind of slow. I guessed that my RAM was full and checked it. And as i suspected its free memory was less. I was shocked just by seeing the total used memory, it was way too high. I tried to trace down the processes but nothing seemed to consume so much.

   So i was assuming that one of the open source application which i was using had some memory leakage. So i wanted to make an investigation on that. All my attempts were failure. So from the experiment i understood the following about memory management in linux.

1. When ever some process is executed after usage it is cached to local storage
2. And this cached memory is not freed automatically.

So i found it, that was the culprit. This cached memory is the one that was occupying the RAM and RAM appeared to be full. So now i would be sharing you the command that would clear the cached memory in RAM and gives your system some space to breathe.

Here it is,

# sync; echo 3 > /proc/sys/vm/drop_caches

Sunday, January 6, 2013

Getting more info on segmentation fault

Hi all,
This is just a very small post which might be useful to you.. Mostly when you develop some codes, especially in some native languages like C, C++, sometimes you face some error "Segmentation Fault (Core Dumped)". This post is all about how we get more info on this when you are working on Linux.

Has anyone wondered what is that called "Core Dumped" that appears after segmentation fault ? and where is it dumped ? :) It is not dumped anywhere unless you enable it.. So we shall learn how to enable it....

Step 1: Change your current directory to temp

# cd /tmp

Step 2: Enable core dump

# ulimit -c unlimited

Step 3: Execute your program in which you face segmentation fault

For example,

# /opt/myprogram.out

It produces,

Segmentation Fault (core dumped)

Thats it, now you have core dumped in /tmp/core file. You can open it with your favorite editor (I prefer vi editor, as other editors crash mostly when you open such binaries).

Note:
The file is a binary and it has more junk info.. parse through the file to check some errors somewhere..