Usage of get_fs and set_fs

  最近在看 drbd的源代码,内核模块 socket通信中有下面一段程序:

  1.  mm_segment_t oldfs;
  2.     struct kvec iov = {
  3.         .iov_base = buf,
  4.         .iov_len = size,
  5.     };
  6.     struct msghdr msg = {
  7.         .msg_iovlen = 1,
  8.         .msg_iov = (struct iovec *)&iov,
  9.         .msg_flags = (flags ? flags : MSG_WAITALL | MSG_NOSIGNAL)
  10.     };
  11.     int rv;
  12.     oldfs = get_fs();
  13.     set_fs(KERNEL_DS);
  14.     rv = sock_recvmsg(sock, &msg, size, msg.msg_flags);
  15.     set_fs(oldfs);

再看看内核中的定义:

  1. #define KERNEL_DS       MAKE_MM_SEG(0xFFFFFFFFUL)
  2. #define USER_DS         MAKE_MM_SEG(PAGE_OFFSET)
  3. #define get_ds()        (KERNEL_DS)
  4. #define get_fs()        (current_thread_info()->addr_limit)
  5. #define set_fs(x)       (current_thread_info()->addr_limit = (x))

其作用是用来修改当前进程的内存访问权限。

      When you make a system call from user space, the first thing that is checked is if the address of the parameter is well within the legal virtual address space (i.e. 0 to 3 GB for the user space). If this is not so, the call will fail. If you want to make the same system call from the Kernel Space( Virtual Address 3 - 4 GB) however, this address checking has to be avoided so that the call will not fail. Now, every process has a tak_struct associated with it and this structure contains the legal virtual address boundaries for that process( Virtual Address space represented by mm_segment_t). The get_fs() macro will retrieve this boundary and the set_fs() will set it with a value. So, when you want to access a memory region which is beyond the User Space Virtual Address limit( i.e. falling in the Kernel Space Virtual Address region)。
set KERNEL_DS when user space address is used

–mkdir: Unknown command Usage: hadoop fs [generic options] [-appendToFile <localsrc> ... <dst>] [-cat [-ignoreCrc] <src> ...] [-checksum <src> ...] [-chgrp [-R] GROUP PATH...] [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...] [-chown [-R] [OWNER][:[GROUP]] PATH...] [-copyFromLocal [-f] [-p] [-l] [-d] <localsrc> ... <dst>] [-copyToLocal [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] [-count [-q] [-h] [-v] [-t [<storage type>]] [-u] [-x] <path> ...] [-cp [-f] [-p | -p[topax]] [-d] <src> ... <dst>] [-createSnapshot <snapshotDir> [<snapshotName>]] [-deleteSnapshot <snapshotDir> <snapshotName>] [-df [-h] [<path> ...]] [-du [-s] [-h] [-x] <path> ...] [-expunge] [-find <path> ... <expression> ...] [-get [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] [-getfacl [-R] <path>] [-getfattr [-R] {-n name | -d} [-e en] <path>] [-getmerge [-nl] [-skip-empty-file] <src> <localdst>] [-help [cmd ...]] [-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [<path> ...]] [-mkdir [-p] <path> ...] [-moveFromLocal <localsrc> ... <dst>] [-moveToLocal <src> <localdst>] [-mv <src> ... <dst>] [-put [-f] [-p] [-l] [-d] <localsrc> ... <dst>] [-renameSnapshot <snapshotDir> <oldName> <newName>] [-rm [-f] [-r|-R] [-skipTrash] [-safely] <src> ...] [-rmdir [--ignore-fail-on-non-empty] <dir> ...] [-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>]] [-setfattr {-n name [-v value] | -x name} <path>] [-setrep [-R] [-w] <rep> <path> ...] [-stat [format] <path> ...] [-tail [-f] <file>] [-test -[defsz] <path>] [-text [-ignoreCrc] <src> ...] [-touchz <path> ...] [-truncate [-w] <length> <path> ...] [-usage [cmd ...]] Generic options supported are: -conf <configuration file> specify an application configuration file -D <property=value> define a value for a given property -fs <file:///|hdfs://namenode:port> specify default filesystem URL to use, overrides 'fs.defaultFS' property from configurations. -jt <local|resourcemanager:port> specify a ResourceManager -files <file1,...> specify a comma-separated list of files to be copied to the map reduce cluster -libjars <jar1,...> specify a comma-separated list of jar files to be included in the classpath -archives <archive1,...> specify a comma-separated list of archives to be unarchived on the compute machines The general command line syntax is: command [genericOptions] [commandOptions]
最新发布
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值