Magenta - Namespace

本文介绍了Magenta操作系统中Namespace的实现原理及其与文件系统的关联。通过客户端和服务端的交互方式,文章详细展示了如何通过namespace-test程序来创建文件和目录的映射,以及如何解决因库文件缺失而导致的应用程序执行失败的问题。

Magenta - Namespace


Magenta的Namespace当前比较简单,只实现了类似于Linux的Mount-space,其他的space隔离暂未看到。Namespace的实现和其文件系统密切相关,后续有机会详细描述,现在只大概说明。

Magenta是以Client/Service的方式实现了文件系统。在devmgr进程中,除了做设备管理之外(device add,device remove, etc),还有1个线程mxio-dispatcher作为文件操作service(open,close,read,write, etc)。其他进程在打开文件时,会通过channel将request发送给service,service执行完文件操作后,将结果返回。

可见在上述的文件架构上,还是很容易实现mount-space的。即本地先创建一个虚拟的文件目录,并将本地的文件映射到service可见的对应的文件即可。


在目前Magenta有个测试程序namespace-test,我们可以实际跑起来看看效果。namespace-test运行时可带参数或不带参数。

当不带参数时,创建如下的映射:

{ "/bin", "/boot/bin" },
{ "/lib", "/boot/lib" },
{ "/fake", "/boot" },
{ "/fake/dev", "/dev" },
{ "/fake/tmp", "/tmp" },
{ "/fake/dev/class/pci/xyz", "/boot/src" },

前者是本地的虚拟文件或目录,后者是root目录下的文件或目录。运行以后,枚举前者目录下的文件,会发现和后者下的文件一样。

我们重点看看带参数运行的情况。

$ namespace-test /bin=/boot/bin
{ .handle = 0x6ce666a3, type = 0x00000020, .path = '/bin' },

在本地只创建1个目录/bin,对应到目录/boot/bin。

$ ls /
d  1        0 bin

可见当前根目录下只有1个目录。

$ ps
/boot/bin/sh: 2: ps: not found
$ echo $PATH
/system/apps:/system/bin:/boot/bin

执行ps失败,是因为/bin目录默认不在PATH路径中,所以未搜索到命令ps。

$ PATH=/system/apps:/system/bin:/boot/bin:/bin
$ ps
dlsvc: could not open 'ld.so.1'
/boot/bin/sh: 5: Cannot create child process: (UNKNOWN): elf_load: handle_interp failed

将/bin目录添加进PATH路径中,可以搜索到ps,但执行失败,因为我们没有映射lib库,导致搜索不到ld.so.1。

我们重新执行namespace-test,将目录/boot/lib也映射。

$ namespace-test /bin=/boot/bin /boot/lib=/boot/lib 
{ .handle = 0x36307b6d, type = 0x00000020, .path = '/boot/lib' },
{ .handle = 0x36f07b69, type = 0x00010020, .path = '/bin' },
$ ls /
d  1        0 bin
d  1        0 boot
$ ls /boot/
d  1        0 lib
$ PATH=/system/apps:/system/bin:/boot/bin:/bin
$ ps
task-utils/walker: cannot open sysinfo: 2
WARNING: walk_root_job_tree failed: ERR_NOT_FOUND (-25)

ps命令还是执行失败,这是因为ps需要读取文件/dev/misc/sysinfo,但我们并未映射目录/dev。

我们重新执行namespace-test,将目录/dev也映射。

$ namespace-test /bin=/boot/bin /boot/lib=/boot/lib /dev=/dev
{ .handle = 0x62cdf50f, type = 0x00000020, .path = '/dev' },
{ .handle = 0x63bdf561, type = 0x00010020, .path = '/boot/lib' },
{ .handle = 0x6045f55f, type = 0x00020020, .path = '/bin' },
$ ls /
d  1        0 bin
d  1        0 boot
d  1        0 dev
$ ps
/boot/bin/sh: 2: ps: not found
$ PATH= PATH=/system/apps:/system/bin:/boot/bin:/bin
$ ps
TASK           PSS PRIVATE  SHARED NAME
j:1028                             root
  p:1043   1373.8k   1372k     28k bin/devmgr
  j:1082                           magenta-drivers
    p:1245  789.8k    788k     28k /boot/bin/acpisvc
    p:1659  249.8k    248k     28k devhost:root
    p:1720  645.8k    644k     28k devhost:misc
    p:1786  253.8k    252k     28k devhost:platform
    p:1955 7329.8k   7328k     28k devhost:pci#1:1234:1111
    p:2017   24.4M   24.4M     28k devhost:pci#3:8086:2922
  j:1103                           magenta-services
    p:1104  293.8k    292k     28k crashlogger
    p:1193  237.8k    236k     28k netsvc
    p:2291  509.8k    508k     28k sh:console
    p:2364  241.8k    240k     28k sh:vc
    p:2498  241.8k    240k     28k sh:vc
    p:2569  237.8k    236k     28k sh:vc
    p:6875  329.8k    328k     28k /boot/bin/namespace-test
    p:6960  381.8k    380k     28k /boot/bin/sh
    p:7047  249.8k    248k     28k /bin/ps
TASK           PSS PRIVATE  SHARED NAME

DONE!

server: port: 8802 # tomcat: # uriEncoding: "UTF-8" # remoteip: # protocol-header-https-value: "https" # remote-ip-header: "RemoteIpValve" # protocol-header: "X-Forwarded-Proto" servlet: context-path: /gateway cors: allowedOrigin: "*" management: endpoints: web: exposure: include: "*" spring: data: redis: client-type: lettuce # 使用响应式客户端 config: import: - "nacos:uap-gateway-test.properties?group=latest&server-addr=uap.qctc.com:8800" - "nacos:common-config.properties?group=latest&server-addr=uap.qctc.com:8800" application: name: uap-gateway main: web-application-type: reactive allow-bean-definition-overriding: true profiles: active: test # group: # latest: [ test ] # 使用数组形式定义包含的profile # 可添加其他组: # production: [prod, metrics] resources: add-mappings: true cloud: config: profile: dev discovery: enabled: true service-id: zhny-config bus: enabled: false trace: enabled: false nacos: # 增加全局日志禁用参数(关键修复) bootstrap: log: enabled: false # 关闭Nacos启动时的日志系统初始化 logging: config: false # 禁用Nacos内部日志配置 naming: false remote: false default: config: enabled: false discovery: server-addr: uap.qctc.com:8801 #uap.qctc.com:8900 11.14.30.16:8848 group: latest config: server-addr: uap.qctc.com:8801 file-extension: properties namespace: public group: latest name: uap-gateway # Data ID prefix: uap-gateway # shared-configs: # - data-id: common-config.properties # group: latest # refresh: true import-check: enabled: false # 禁用导入检查(可选) gateway: # 全局连接池与超时配置 httpclient: retry: false # 全局关闭重试 # 允许特殊字符 relaxed-cookies: true pool: max-connections: 2000 # 最大总连接数 [2,5](@ref) max-idle-time: 50000ms # 连接空闲超时 connect-timeout: 50000 # 连接超时(毫秒)[2](@ref) response-timeout: 50000 # 响应超时(毫秒)[2](@ref) protool: h2c keepalive: true # 全局跨域配置(按需启用) globalcors: add-to-simple-url-handler-mapping: true cors-configurations: '[/**]': allowed-origins: "*" allow-credentials: false # 保持凭证携带 allowed-methods: "GET,POST" allowedMethods: "GET,POST" allowed-headers: "*" max-age: 3600 # 预检请求缓存时间 # 全局默认过滤器:移除 /api 前缀 [1,4](@ref) default-filters: - RewritePath=/api/(?<segment>.*), /$\{segment} discovery: locator: enabled: true # 开启从注册中心动态创建路由的功能,利用微服务名进行路由 routes: - id: gateway_self_api uri: no://op # 特殊标记,表示不转发 predicates: - Path=/gateway/api/isLicenseOverdue filters: - SetPath=/ # 内置过滤器(仅作占位符) # - id: gateway_prefix_route # uri: lb://uap-base # predicates: # - Path=/gateway/api/uap/** # filters: # - StripPrefix=2 # 移除 /gateway/api,保留 /uap/... # 1. uap-base 服务 - id: base uri: lb://uap-base predicates: - Path=/gateway/api/uap/** filters: - StripPrefix=2 - id: customer uri: lb://uap-base predicates: - Path=/gateway/api/customer/** filters: - StripPrefix=2 # 2. zhny-publish-test 服务 - id: market uri: lb://zhny-publish-test predicates: - Path=/gateway/api/market/** filters: - StripPrefix=2 - id: cmsservice uri: lb://zhny-publish-test predicates: - Path=/gateway/api/cmsservice/** filters: - StripPrefix=2 - id: sns uri: lb://zhny-publish-test predicates: - Path=/gateway/api/sns/** filters: - StripPrefix=2 - id: trade uri: lb://zhny-publish-test predicates: - Path=/gateway/api/trade/** filters: - StripPrefix=2 - id: settle uri: lb://zhny-publish-test predicates: - Path=/gateway/api/settle/** filters: - StripPrefix=2 - id: vpp uri: lb://zhny-publish-test predicates: - Path=/gateway/api/vpp/** filters: - StripPrefix=2 - id: nbxy uri: lb://zhny-publish-test predicates: - Path=/gateway/api/nbxy/** filters: - StripPrefix=2 - id: pla uri: lb://zhny-publish-test predicates: - Path=/gateway/api/pla/** filters: - StripPrefix=2 # 3. 其他独立服务 - id: analysis # zhny-esf uri: lb://zhny-publish-test predicates: - Path=/gateway/api/analysis/** filters: - StripPrefix=2 - id: dta # zhny-dta uri: lb://zhny-dta predicates: - Path=/gateway/api/dta/** filters: - StripPrefix=2 - id: crd # zhny-crd uri: lb://zhny-crd predicates: - Path=/gateway/api/crd/** filters: - StripPrefix=2 - id: hnsd # zhny-hnsd uri: lb://zhny-hnsd predicates: - Path=/gateway/api/hnsd/** filters: - StripPrefix=2 - id: grc # zhny-grc uri: lb://zhny-grc predicates: - Path=/gateway/api/grc/** filters: - StripPrefix=2 - id: ecarbon # zhny-ecarbon uri: lb://zhny-ecarbon predicates: - Path=/gateway/api/ecarbon/** filters: - StripPrefix=2 - id: rpt # zhny-rpt uri: lb://zhny-rpt predicates: - Path=/gateway/api/rpt/** filters: - StripPrefix=2 - id: gdt # zhny-gdt uri: lb://zhny-gdt predicates: - Path=/gateway/api/gdt/** filters: - StripPrefix=2 - id: ems # zhny-ems uri: lb://zhny-ems predicates: - Path=/gateway/api/ems/** filters: - StripPrefix=2 - id: ecm # zhny-ecm uri: lb://zhny-ecm predicates: - Path=/gateway/api/ecm/** filters: - StripPrefix=2 - id: hbvpp # zhny-hbvpp uri: lb://zhny-hbvpp predicates: - Path=/gateway/api/hbvpp/** filters: - StripPrefix=2 - id: gcd # zhny-gcd uri: lb://zhny-publish-test predicates: - Path=/gateway/api/gcd/** filters: - StripPrefix=2 - id: hbdkclient # zhny-hbdkclient uri: lb://zhny-hbdkclient predicates: - Path=/gateway/api/hbdkclient/** filters: - StripPrefix=2 - id: fhjhjy # zhny-fhjhjy uri: lb://zhny-fhjhjy predicates: - Path=/gateway/api/fhjhjy/** filters: - StripPrefix=2 - id: sdpxvpp # sd-sdpxvpp uri: lb://sd-sdpxvpp predicates: - Path=/gateway/api/sdpxvpp/** filters: - StripPrefix=2 - id: dts # zhny-dts uri: lb://zhny-dts predicates: - Path=/gateway/api/dts/** filters: - StripPrefix=2 - id: rec # zhny-rec uri: lb://zhny-rec predicates: - Path=/gateway/api/rec/** filters: - StripPrefix=2 - id: ptc # zhny-ptc uri: lb://zhny-ptc predicates: - Path=/gateway/api/ptc/** filters: - StripPrefix=2 - id: lmp # zhny-lmp uri: lb://zhny-publish-test predicates: - Path=/gateway/api/lmp/** filters: - StripPrefix=2 eureka: client: fetch-registry: true # 必须显式启用 register-with-eureka: true # 必须显式启用 healthcheck: enabled: false serviceUrl: defaultZone: http://qctczhny:QCTCzhny6608!@uap.qctc.com:8800/eureka instance: metadata-map: management: context-path: ${server.servlet.context-path}/actuator prefer-ip-address: true instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${spring.application.instance_id:${server.port}} lease-renewal-interval-in-seconds: 2 #续约间隔 lease-expiration-duration-in-seconds: 4 #租约寿命 #status-page-url: http://${spring.cloud.client.ip-address}:${server.port}/api/doc.html health-check-url-path: ${server.servlet.context-path}/actuator/health #swagger: # enabled: true # name: QCTC统一开发平台 #api名称 # description: QCTC统一开发平台接口文档说明 #api描述 # termsOfServiceUrl: http://uap.qctc.com:8802${server.servlet.context-path} # developer: QCTC #api开发 # version: 3.0.0 #api开发 # basic: # enable: true # username: qctc # password: qctcadmin6608 feign: # 启用 Resilience4j circuitbreaker: enabled: true group: enabled: true httpclient: enabled: false okhttp: enabled: true compression: request: enabled: true mime-types: text/html,text/xml,text/plain,application/xml,application/json response: enabled: true # 定义客户端超时 client: config: default: # 全局默认配置 connectTimeout: 5000 # 连接超时(ms) readTimeout: 10000 # 读取超时(ms) # 绑定熔断器和超时器 resilience4jCircuitBreakerName: default resilience4jTimelimiterName: default ####超时配置#### resilience4j: circuitbreaker: instances: default: # 默认熔断器配置(作用于所有 Feign 调用) failureRateThreshold: 50 # 失败率阈值% minimumNumberOfCalls: 10 # 最小调用次数 slidingWindowType: COUNT_BASED slidingWindowSize: 10 # 统计窗口大小 waitDurationInOpenState: 10s # 熔断持续时间 timelimiter: instances: default: timeoutDuration: 5s # 单次调用超时时间 # 日志 logging: file: name: /usr/qctcapps/gateway/data/${spring.application.name}/debug.log #/usr/qctcapps/publish_test pattern: file: "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx" level: root: info com.qctc.uap: info # com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder: DEBUG # org.springframework.core.env.PropertySourcesPropertyResolver: DEBUG # org.springframework.cloud.gateway.filter: TRACE # reactor.netty.http.client: DEBUG 配置有问题吗
09-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值