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 ...
随机推荐
- bootbox.js官方文档中文版
bootbox.js官方文档中文版简介:Bootbox.js是一个小型的JavaScript库,基于Bootstrap模态框开发,用于创建可编程的对话框. 不像原生的alert等对话框,所有的Boot ...
- 71A
#include <iostream> #include <string> using namespace std; int main() { string word; int ...
- Java创建文件夹
import java.io.File; public class Mkdirs { public static void main(String[] args) { /** *创建文件夹,如果路径不 ...
- 自动出借-python+selenium
自动出借 import time from selenium import webdriver # import os #B username = " # 请替换成你的用户名 passwor ...
- node代码打包为 exe文件---端口进程关闭demo
最近用到 java,用tomcat起的服务,经常服务关了,对应的进程还在跑,导致再次启动服务失败,需要手动关闭进程. 使用 dos命令虽然只有两行,总是输,也很烦. netstat -ano | fi ...
- 23个适合logo设计的常用英文字体
在很多国外的品牌中我们都会发现他们的英文字体在logo的运用中,不仅会提升logo的品质还会让logo看起来更加美观.今天我们就来看看都有哪些常常出现在logo设计中的英文字体吧. 字体,与文字本 ...
- 关于设置cookie同源,axios请求加上cookie
一个有cookie 一个没有 这是为啥!! axios都设置了的为true允许携带cookie 大佬答疑解惑:==>cookie同源域名才有啊,在Application看看cookie的pat ...
- filename
package com.enjoyor.soa.traffic.server.tms.controller; import java.io.BufferedReader;import java.io. ...
- WebSocket.之.基础入门-后端响应消息
WebSocket.之.基础入门-后端响应消息 在<WebSocket.之.基础入门-前端发送消息>的代码基础之上,进行添加代码.代码只改动了:TestSocket.java 和 inde ...
- HttpServletRequest常用方法
1.获取客户机信息 getRequestURL:该方法返回客户端发出请求时的完整URL getRequestURI:该方法返回请求行中的资源名部分 getQueryString:该方法返回请求中的参数 ...