ltp-fcntl36 偶尔出现fail unexpected data offset 20928 value 94
每次出错的都是和posix相关
先把结论说了:
fn_ofd_w和fn_ofd_r的SAFE_FCNTL参数F_OFD_SETLKW
fn_posix_w和fn_posix_r的SAFE_FCNTL参数F_SETLKW
四个函数都用的flock64结构体
case F_SETLK:
case F_SETLKW:
err = get_compat_flock(&flock, compat_ptr(arg));
case F_SETLK64:
case F_SETLKW64:
case F_OFD_SETLK:
case F_OFD_SETLKW:
err = get_compat_flock64(&flock, compat_ptr(arg));
显然posix调用get_compat_flock,传入的却是flock64
The original Linux fcntl() system call was not designed to handle large file offsets (in the flock structure).
Consequently, an fcntl64() system call was added in Linux 2.4. The newer system call employs a different structure for file locking, flock64, and corresponding commands, F_GETLK64, F_SETLK64, and F_SETLKW64. However, these details can be ignored by applications using glibc, whose fcntl() wrapper function transparently employs the more recent system call where it is available.
措施:fn_posix_w和fn_posix_r的
struct flock64 lck = {
.l_whence = SEEK_SET,
.l_start = pa->offset,
.l_len = pa->length,
.l_pid = 0,
};
改为
struct flock lck = {
.l_whence = SEEK_SET,
.l_start = pa->offset,
.l_len = pa->length,
.l_pid = 0,
};
static int thread_cnt;
static int fail_flag = 0;
static volatile int loop_flag = 1;
static const int max_thread_cnt = 32;
static const char fname[] = "tst_ofd_posix_locks"; //文件名
static const long write_size = 4096;
static pthread_barrier_t barrier;
struct param {
long offset;
long length;
long cnt;
};
thread_cnt = tst_ncpus_conf() * 3; //四核 4*3=12
if (tst_fill_file(fname, 1, write_size, thread_cnt + 1))
写4096 (4+1)次 写入fname 写入1
if (pthread_barrier_init(&barrier, NULL, thread_cnt*3) != 0)
初始化屏障结构函数,设计屏障等待的最大线程数目(4*3)
for (i = 0; i < thread_cnt; i++) {
p0[i].offset = i * write_size;
p0[i].length = write_size;
p0[i].cnt = i + 2;
p1[i].offset = i * write_size + write_size / 4;
p1[i].length = write_size;
p1[i].cnt = i + 2;
p2[i].offset = i * write_size + write_size / 2;
p2[i].length = write_size;
p2[i].cnt = i + 2;
}
P0[0]={0,4096,2}
P1[0]={1024,4096,2}
P2[0]={2048,4096,2}
P0[1]={4096,4096,3}
P1[1]={5120,4096,3}
P2[1]={6144,4096,3}
P0[2]={8192,4096,4}
P1[2]={9216,4096,4}
P2[2]={10240,4096,4}
P0[3]={12288,4096,5}
P1[3]={13312,4096,5}
P2[3]={14336,4096,5}
fail_flag = 0;
loop_flag = 1;
for (i = 0; i < thread_cnt; i++) {
SAFE_PTHREAD_CREATE(id0 + i, NULL, f0, (void *)&p0[i]);
SAFE_PTHREAD_CREATE(id1 + i, NULL, f1, (void *)&p1[i]);
SAFE_PTHREAD_CREATE(id2 + i, NULL, f2, (void *)&p2[i]);
}
static struct tcase {
void *(*fn0)(void *);
void *(*fn1)(void *);
void *(*fn2)(void *);
const char *desc;
} tcases[] = {
{fn_ofd_r, fn_ofd_w, fn_dummy, "OFD read lock vs OFD write lock"},
{fn_ofd_w, fn_posix_w, fn_dummy, "OFD write lock vs POSIX write lock"},
{fn_ofd_r, fn_posix_w, fn_dummy, "OFD read lock vs POSIX write lock"},
{fn_ofd_w, fn_posix_r, fn_dummy, "OFD write lock vs POSIX read lock"},
{fn_ofd_w, fn_ofd_w, fn_dummy, "OFD write lock vs OFD write lock"},
{fn_ofd_r, fn_ofd_w, fn_posix_w, "OFD r/w lock vs POSIX write lock"},
{fn_ofd_r, fn_ofd_w, fn_posix_r, "OFD r/w lock vs POSIX read lock"},
};
offset length cnt
建立以下线程
fn_ofd_r p00 P0[0]={0,4096,2}
fn_ofd_w p10 P1[0]={1024,4096,2}
fn_dummy p20 P2[0]={2048,4096,2}
fn_ofd_r p01 P0[1]={4096,4096,3}
fn_ofd_w p11 P1[1]={5120,4096,3}
fn_dummy p21 P2[1]={6144,4096,3}
fn_ofd_r p02 P0[2]={8192,4096,4}
fn_ofd_w p12 P1[2]={9216,4096,4}
fn_dummy p22 P2[2]={10240,4096,4}
fn_ofd_r p03 P0[3]={12288,4096,5}
fn_ofd_w p13 P1[3]={13312,4096,5}
fn_dummy p23 P2[3]={14336,4096,5}
/* OFD read lock reading data*/
static void *fn_ofd_r(void *arg)
{
struct param *pa = arg;
//pa P0[0]={0,4096,2} offset length cnt
unsigned char buf[pa->length];//4096
int i;
int fd = SAFE_OPEN(fname, O_RDWR);
struct flock64 lck = {
.l_whence = SEEK_SET,
.l_start = pa->offset,
.l_len = pa->length,
.l_pid = 0,
};
while (loop_flag) {
memset(buf, 0, pa->length);
lck.l_type = F_RDLCK;
SAFE_FCNTL(fd, F_OFD_SETLKW, &lck);
/* rlock acquired */
SAFE_LSEEK(fd, pa->offset, SEEK_SET);
SAFE_READ(1, fd, buf, pa->length);
/* Verifying data read */
for (i = 0; i < pa->length; i++) {
//buf的值介于1-254之间
if (buf[i] < 1 || buf[i] > 254) {
tst_res(TFAIL, "Unexpected data "
"offset %ld value %d",
pa->offset + i, buf[i]);
fail_flag = 1;
break;
}
//buf 1024字节之内的数值应该一致,除法取整
int j = (i / (pa->length/4)) * pa->length/4;
if (buf[i] != buf[j]) {
tst_res(TFAIL, "Unexpected data "
"offset %ld value %d",
pa->offset + i, buf[i]);
fail_flag = 1;
break;
}
}
lck.l_type = F_UNLCK;
SAFE_FCNTL(fd, F_OFD_SETLK, &lck);
sched_yield();
}
pthread_barrier_wait(&barrier);
SAFE_CLOSE(fd);
return NULL;
}
/* OFD write lock writing data*/
static void *fn_ofd_w(void *arg)
{
struct param *pa = arg;
//pa P1[0]={1024,4096,2} offset length cnt
unsigned char buf[pa->length];
int fd = SAFE_OPEN(fname, O_RDWR);
long wt = pa->cnt;
struct flock64 lck = {
.l_whence = SEEK_SET,
.l_start = pa->offset,
.l_len = pa->length,
.l_pid = 0,
};
while (loop_flag) {
memset(buf, wt, pa->length);
lck.l_type = F_WRLCK;
SAFE_FCNTL(fd, F_OFD_SETLKW, &lck);
SAFE_LSEEK(fd, pa->offset, SEEK_SET);
SAFE_WRITE(1, fd, buf, pa->length);
lck.l_type = F_UNLCK;
SAFE_FCNTL(fd, F_OFD_SETLKW, &lck);
wt++;
if (wt >= 255)
wt = pa->cnt;
sched_yield();
}
pthread_barrier_wait(&barrier);
SAFE_CLOSE(fd);
return NULL;
}
//啥也不干
static void *fn_dummy(void *arg)
{
arg = NULL;
pthread_barrier_wait(&barrier);
return arg;
}
ltp-fcntl36 偶尔出现fail unexpected data offset 20928 value 94的更多相关文章
- linux内核启动时报错ubi0 error: validate_ec_hdr: bad data offset 256, expected 128
1.错误解析 ubi的EC header中有一个字段data_offset来记录数据偏移,数据偏移必须正确才能正确读取每一个物理擦除块中的数据 2.解决方法 擦除整块flash,然后再重新烧写包含ub ...
- [转贴]LTP--linux稳定性测试 linux性能测试 ltp压力测试 ---IBM 的 linux test project
https://blog.csdn.net/melody157398/article/details/24354415 LTP--linux稳定性测试 linux性能测试 ltp压力测试 ---I ...
- LTP(LinuxTest Project)测试工具
LTP(LinuxTest Project)是SGI.IBM.OSDL和Bull合作的项目,目的是为开源社区提供一个测试套件,用来验证Linux系统可靠性.健壮性和稳定性.LTP测试套件是测试Linu ...
- LTP--linux稳定性测试 linux性能测试 ltp压力测试 ---IBM 的 linux test project
LTP--linux稳定性测试 linux性能测试 ltp压力测试 ---IBM 的 linux test project Peter盼 2014-04-23 11:25:49 20302 收藏 ...
- LTP--linux稳定性测试 linux性能测试 ltp压力测试 内核更新 稳定性测试
LTP--linux稳定性测试 linux性能测试 ltp压力测试 zhangzj1030关注14人评论33721人阅读2011-12-09 12:07:45 说明:在写这篇文章之前,本人也不曾了 ...
- LTP--linux稳定性测试 linux性能测试 ltp压力测试 ltp-pan
LTP--linux稳定性测试 linux性能测试 ltp压力测试 zhangzj1030关注14人评论33710人阅读2011-12-09 12:07:45 说明:在写这篇文章之前,本人也不曾了 ...
- LTP介绍
1.LTP介绍 LTP--linut test project ,ltp套件是由Linux Test Project所开发的一套系统測试套件.它基于系统资源的利用率统计开发了一个測试的组合,为系 ...
- Offset Management For Apache Kafka With Apache Spark Streaming
An ingest pattern that we commonly see being adopted at Cloudera customers is Apache Spark Streaming ...
- kafka使用getOffsetsBefore()获取获取offset异常分析
根据时间戳获取kafka的topic的偏移量,结果获取的偏移量量数据组的长度为0,就会出现如下的数组下标越界的异常,实现的原理是使用了kafka的getOffsetsBefore()方法: Excep ...
随机推荐
- Oracle下SQL学习笔记
主机字符串:as sysdba alter user scott account unlock;//解锁scott,不会就谷歌检索 DML语句,增.删.查.改 select语句:熟悉表结构 desc ...
- cookie存值 后取值是string string字符串转对象
实现方法 // 得到 对象 格式或 json 格式的一个字符串 var str = '{"name":"张根硕","age":"1 ...
- Centos7安装Openvpn
前言 搭建openvpn主要参考这篇博客,原文传送: http://www.jianshu.com/p/4bbf946222d5 所以你会发现步骤基本一样. 安装openvpn A:安装EPEL仓库 ...
- Java元注解—— @Retention @Target @Document @Inherited
java中元注解有四个: @Retention @Target @Document @Inherited: @Retention:注解的保留位置 @Retention(RetentionPolicy. ...
- (转)面试必备技能:JDK动态代理给Spring事务埋下的坑!
一.场景分析 最近做项目遇到了一个很奇怪的问题,大致的业务场景是这样的:我们首先设定两个事务,事务parent和事务child,在Controller里边同时调用这两个方法,示例代码如下: 1.场景A ...
- ssh tunnel 三种模式
环境介绍: 主机 位置 公网 内网IP 角色 host-a 局域网1 否 192.168.0.1 ssh client host-b 局域网2.公网 是 192.168.1.1 ssh server ...
- mysql 延迟添加唯一索引
MySQL [test]> create table tbl_keyword ( -> id int not null auto_increment primary key, -> ...
- python 判断字符串是否包含子字符串
第一种方法:in string = 'helloworld' if 'world' in string: print 'Exist' else: print 'Not exist' 第二种方法:fin ...
- vue中检测敏感词,锚点
当发布文章的时候,标题有敏感词 则检测有敏感词的接口成功的时候,写锚点 eg: _this .$alert("检测到标题有敏感词,请修改后再发布", "提示", ...
- Lua class
local _class = {} function class(super) local class_type = {} class_type.ctor = false class_type.sup ...