`
javasee
  • 浏览: 977583 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

A brief introduction to XenBus from the perspective of the driver

阅读更多

Writing Xen Drivers: Using XenBus and XenStore

XenBus provides a bus abstraction for paravirtualized drivers to communicate between domains. In practice, the bus is used for configuration negotiation, leaving most data transfer to be done via an interdomain channel composed of a shared page and an event channel.

Xenstore is a centralized configuration database that is accessible by all domains. Management tools configure and control virtual devices by writing values into the database that trigger events in drivers.

Driver and tool developers should use this document as a guide for bringing Xenbus and Xenstore functionality into their code.

Xenbus: Drivers

All conventional Xen virtual device drivers should register themselves with the XenBus at initialization. This is done by passing an appropriately initialized xenbus_driverstruct to the xenbus_register_driver() function. Most internal initialization and setup should be postponed until the Xenbus calls the probe callback function.

In the case of a traditional split Xen driver, such as the block driver, the communication between the front and back ends should be established when the probe callback is executed. The block driver is a good example for developers wishing to see an actual implementation (see linux-2.6-xen-source/drivers/xen/blkfront/blkfront.c )

Other drivers

Some drivers, such as the balloon driver, don't fit into the conventional split-driver mold (meaning they don't have front and back ends). These drivers don't register with the Xenbus in the normal way, and therefore don't ever get a probe callback to initialize themselves once the store is up. These drivers should instead call register_xenstore_notifier() to register a notifier callback that can perform store-related initialisation.

Xenstore: Drivers and Tools

The Xenstore is a filesystem-like database that is used by Xen applications and drivers to communicate and store configuration information. Applications and tools should use the store to configure drivers by writing information into keys in the database; drivers should set watches on the appropriate keys and respond to changes appropriately.

As a general rule, users of the store should attempt to use human-readable values whenever possible. This allows a generic browser tool (think gconf-editor) to be used to examine the contents of the store. For example, Xend could instruct the shutdown driver to power off by writing a "0" into the appropriate store key. This works, but makes it hard for a viewer to know what "0" means. Instead, Xend writes "poweroff" or "reboot" into the key, which makes it clear to an observer what action is intended.

Using XenStore

Reading and Writing data

The Xenstore API provides methods for manipulating data in the store that resemble standard C functions:

xenbus_printf(DIR, NODE, FORMAT, ...)
xenbus_scanf(DIR, NODE, FORMAT, ...)
xenbus_rm(DIR, NODE)
xenbus_read(DIR, NODE, &LEN)

Developers should use these functions to read and write data in the store. Nodes that do not already exist will be created by a xenbus_printf() . When reading a variable-length string value from a store key, xenbus_read() should be used, which returns a kmalloc 'd buffer containing the string. This string should be kfree 'd after use.

Transactions

Transactions provide developers with a method for ensuring that multiple operations on the Xenstore are seen as a single atomic operation. Any time multiple operations must be performed before any changes are seen by watchers, a transaction must be used to encapsulate the changes. For example:

xenbus_transaction_start("mydir");
xenbus_printf("mydir", "command", "%s", "do_something");
xenbus_printf("mydir", "arg", "%s", "14");
xenbus_transaction_end(0);

Watches

A "watch" can be placed on a key in the XenStore which causes a callback function to be executed whenever something changes at or below the level where the watch was placed. This allows drivers or applications to respond immediately to changes in the store. For example, the balloon driver watches "memory/target " and immediately attempts to balloon the domain's memory whenever a new target is written to the key:

static struct xenbus_watch xb_watch = {
.node = "memory",
.callback = watch_target;
};
ret = register_xenbus_watch(&xb_watch);
if(IS_ERR(ret)) {
IPRINTK("Failed to initialize balloon watcher\n");
} else {
IPRINTK("Balloon xenbus watcher initialized\n");
}

Xenstore Rules and Standards

There are several things developers need to be aware of when utilizing the Xenstore:

General:

  • No data that is written into the Xenstore from DomU kernels or tools should be trusted or considered correct by the Dom0 kernel or system management tools.
  • When writing drivers, care must be given to the Dom0 case. When Dom0 boots, the Xenbus and Xenstore are not active; therefore, they must not be used.
  • Directories and (when possible) keys should be created by the tools, instead of the kernel.

Store organization:

  • All routines should specify relative paths in Xenstore calls, which results in a path relative to the "home directory" of the domain within the store.
  • Information should not be replicated in the store and required to be consistent

Permissions

Any guest can read any part of the store, but only if it has permission to do so. Domain 0 may read or write anywhere in the store, regardless of permissions, and permissions are set up by the tools in domain 0, or by Xenstored when it first starts up.

The permission semantics for Xenstore are a bit strange; here they are:

There are calls in the Python layer -- xstransact.SetPermissions and xstransact.set_permissions -- and a corresponding C layer call -- xs_set_permissions -- each of which takes a path, and a list of (domid, permissions) pairs. I shall use the Python syntax, as this is clearer. In this case, read and write flags are specified, which are packed into the "permissions" field in the tuple.

xstransact.SetPermissions(path, { 'dom'   : dom1,
'read' : True,
'write' : False },
{ 'dom' : dom2,
'read' : True,
'write' : True },
{ 'dom' : dom3,
'read' : True,
'write' : True })

This looks clear, but actually the semantics of this are strange. The first element in this list specifies the owner of the path, plus the read and write access flags for every domain unspecified subsequently . The owner always has read and write access to their nodes. The subsequent entries are normal capabilities. The example above, therefore, sets the permissions on the path to be such that domain 0 (being privileged), dom1 (being the owner), and domains dom2 and dom3 (being explicitly specified) can _all_ write to the node. Any other domain can only read, as specified by the first pair of 'read' and 'write' flags.

Finally, please note that permissions in the store are inherited from parent to child, but only when the child is created. This means that if you do

write('/tool/mytool/foo', 'Hi')
write('/tool/mytool/bar', 'Hello')
set_perms('/tool/mytool', { 'dom' : 0,
'read' : True,
'write' : True })

then foo and bar will not necessarily be read/write everybody! They will instead have the permissions of /tool/mytool at the time of the writes, so if /tool/mytool did not exist at the time, then foo and bar will be unreadable by anyone except dom0 and the domain that created them.

Xend is careful to do

rm('/local/domain/<domid>')
mkdir('/local/domain/<domid>')
set_perms('/local/domain/<domid>', { 'dom' : <domid> })

for this very reason.

N.B.: Changes subject to http://wiki.xensource.com/xenwiki/XenBus

分享到:
评论

相关推荐

    神经网络简介A Brief Introduction to Neural Networks

    神经网络作为一种重要的机器学习模型,在计算机科学领域内占据了举足轻重的地位。本文将基于给定文件中的信息,深入探讨神经网络的基本概念、发展历程、主要类型及其应用领域,旨在为读者提供一个全面而深入的理解。...

    A Brief Introduction to PySpark

    关于 PySpark 的简介,适合新手入门学习。PySpark is a great language for performing exploratory data ... The goal of this post is to show how to get up and running with PySpark and to perform common tasks.

    A brief introduction to weakly supervised learning.pdf

    Supervised learningtechniques construct predictive models by learning from a large number of training examples, where each training example has a label indicating its ground-truth output. Though ...

    A Brief Introduction to Machine Learning for Engineers

    A Brief Introduction to Machine Learning for Engineers is the entry point to machine learning for students, practitioners, and researchers with an engineering background in probability and linear ...

    a brief introduction to opennp

    OpenMP是一个支持多平台共享内存并行编程的API,它能够在C/C++和Fortran语言中使用。它提供了一组编译制导(编译指导语句)、库函数和环境变量,用以简化多线程的开发。OpenMP以简洁的方式实现了线程的创建、分配...

    A brief Introduction to Neural Networks

    文章提到的标题“A brief Introduction to Neural Networks”(神经网络简介),内容提到了神经网络的原理、结构、学习过程等基础知识,以及以Java语言编写的神经网络框架。文中强调了神经网络的学习目的在于为读者...

    A Brief Introduction to Boosting

    ### 提升算法(Boosting)简介 #### 一、引言 提升算法(Boosting)是一种通用的方法,用于提高任何给定学习算法的准确性。它最初源于理论框架下的研究,即所谓的“PAC”(Probably Approximately Correct)学习模型...

    a brief introduction to index theorems

    指标定理的介绍,来自知乎蓝青的论文,图片归集成pdf,便于阅读

    Think OS: A Brief Introduction to Operating Systems

    《Think OS:操作系统简明入门》是Allen B. Downey所著的一本入门级操作系统教材,主要面向那些对操作系统设计和实现感兴趣的读者。该书不仅涵盖了操作系统的基础知识,还通过实际案例和示例程序,帮助学生和自学者...

    An Introduction to the Mathematics of Financial Derivatives

    在提供的部分内容中,我们能看到几个关键词和短语,例如“Financial Derivatives—A Brief Introduction”、“Pricing Derivatives: Models and Notation”以及“List of Symbols and Acronyms”。这些短语提示我们...

    An Introduction to Project Management With a Brief Guide to Microsoft epub

    An Introduction to Project Management With a Brief Guide to Microsoft Project 2013(5th) 英文epub 第5版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或...

    Think OS:操作系统简介Think OS: A Brief Introduction to Operating Systems

    Think OS是面向程序员的操作系统介绍。 计算机架构知识不是先决条件。

    人工智能的教育意义简介Brief Introduction to Educational Implications of Artificial Intelligence

    这本简短的书介绍了人类如何利用人工智能来解决问题和完成任务。

    A Brief Introduction to Machine Learning

    在给定的文件中,作者Osvaldo Simeone在其著作《A Brief Introduction to Machine Learning for Engineers》(工程师的机器学习简明入门)中,为我们提供了一个系统性的机器学习概念介绍,其中包括了监督学习、非...

    NoSQL Distilled - A Brief Guide to the Emerging World of Polyglot Persistence

    本书的标题“**NoSQL Distilled – A Brief Guide to the Emerging World of Polyglot Persistence**”准确地概括了其核心内容与目标受众。NoSQL(Not Only SQL)是指非关系型数据库系统,这类系统不依赖于传统的SQL...

    A brief introduction to MetaPost

    vardef spiral(expr n, a, b) = if n &gt; 0: a for i = 1 upto n: -- b rotatedaround((0, 0), 90 * i) .. fi enddef; ``` #### 25. 递归路径 递归路径是 MetaPost 中的一种特殊类型的路径,它可以用来构建复杂的...

    A_Brief_Introduction_to_Sigma_Delta_Conversion

    标题与描述:“A Brief Introduction to Sigma Delta Conversion”的深入解析 标题和描述中提及的“Sigma Delta Conversion”(ΣΔ转换)是一种在模拟信号与数字信号之间进行转换的技术,尤其是在低带宽信号转换中...

    A Brief Introduction to Scala

    ### Scala简介:结合函数式与面向对象编程的强大语言 #### Scala概述 Scala是一种相对新兴的编程语言,旨在为Java虚拟机(JVM)以及后来的通用语言运行时(CLR)提供支持。它融合了函数式编程(Functional Programming,...

    A Brief Introduction to Sigma Delta Conversion.pdf

    The sigma delta conversion technique has been in ... This application note is intended to give an engineer with little or no sigma delta background an overview of how a sigma delta converter works

Global site tag (gtag.js) - Google Analytics