顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

星期六, 3月 10, 2007

NFS exports FUSE problem

It is a known problem since, at least 2003, but haven't been fixed so far.

A patch for fuse kernel modules is available here.

Discussion on FUSE list.

If you try to export FUSE file system over NFS, you would see error message in daemon.log like this:

Mar 2 13:49:46 235-194 mountd[3211]: authenticated mount request from nb:907 for /mnt/sdb3 (/mnt/sdb3)
Mar 2 13:49:46 235-194 mountd[3211]: getfh failed: Operation not permitted

To be able to export over NFS, a file system driver should implement export_operations functions.

iptables SAME target

The history of SAME is to make a target act like SNAT, but choose the SAME source address for SAME destination address.

Before kernel 2.6.11 you could specify more than one --to-source option for SNAT, kernel will choose any of these addresses to do NAT. After 2.6.11 you could still assign a block of continuous address in --to-source, for example --to-source 192.168.0.1-192.168.0.5. But you can not assign multiple --to-source like --to-source 192.168.0.1 --to-source 192.168.1.1.

Instead, you should use SAME target,
iptables -A POSTROUTING -j SAME --to-source 192.168.0.1 --to-source 192.168.1.1
This gives a client the same source-/destination address for each connection.

星期六, 9月 09, 2006

Pthread conditional wait

When writing multi-thread program, you may want to wait until another thread finished to continue the current thread. You can use pthread_join after a thread has been created.

int retm=pthread_create(&main_thread,NULL,init_gtk_thread,(void *)0);
pthread_join(main_thread,NULL);

The current thread will be blocked until main_thread finished by calling pthread_exit or return.

But when you want to wait until some condition met, you will need to use a condition variable and a mutex .

Example

int x,y;
pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
Thread 1 - wait until x>y
pthread_mutex_lock(&mut);
while (x <= y) { pthread_cond_wait(&cond, &amp;mut); } /* operate on x and y */ pthread_mutex_unlock(&mut);
Thread 2 - modify x and y
pthread_mutex_lock(&mut);
while(x<=y)x++; if (x > y) pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mut);

  1. mutex mut protects variables x and y.
  2. pthread_cond_wait will unlock mut and go to sleep and waits for the condition variable cond to be signalled.
  3. thread 2 signal cond by calling pthread_cond_signal or pthread_cond_broadcast
P.S. Pthread-win32 is here